-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw7-1.cpp
54 lines (49 loc) · 1.09 KB
/
hw7-1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
int biggestDigit(int x) {
int d, max=0;
while (x>0) {
d=x%10;
if (d>max)
max=d;
x=x/10;
}
return max;
}
void anyPrime(int x) {
for (int n=2; n<=x; n++) {
int counter=0;
for (int i=2; i<n; i++) {
if(n%i==0) {
counter++;
}
}
if (counter==0)
cout << n << " ";
}
}
bool isPrime(int x) {
for (int i=2; i<x; i++) {
if(x%i==0)
return false;
}
return true;
}
int main() {
int x;
bool y;
cout << "Enter a positive integer x greater than 1000: ";
cin >> x;
while (x<=1000) {
cout << "Invalid, enter a positive integer x greater than 1000: ";
cin >> x;
}
cout << "The biggest digit in " << x << " is: " << biggestDigit(x) << endl;
y=isPrime(x);
if (y==true) cout << x << " is a prime number: True" << endl;
else cout << x << " is a prime number: False" << endl;
cout << "The prime numbers from 1 to 100 are: ";
anyPrime(100);
cout << endl;
return 0;
}