1#include <iostream>
2using namespace std;
3
4int main()
5{
6 int n, i;
7 bool isPrime = true;
8
9 cout << "Enter a positive integer: ";
10 cin >> n;
11
12 for(i = 2; i <= n / 2; ++i)
13 {
14 if(n % i == 0)
15 {
16 isPrime = false;
17 break;
18 }
19 }
20 if (isPrime)
21 cout << "This is a prime number";
22 else
23 cout << "This is not a prime number";
24
25 return 0;
26}
1#include <iostream>
2using namespace std;
3
4int main() {
5 int low, high, i;
6 bool isPrime = true;
7
8 cout << "Enter two numbers (intervals): ";
9 cin >> low >> high;
10
11 cout << "\nPrime numbers between " << low << " and " << high << " are: " << endl;
12
13 while (low < high) {
14 isPrime = true;
15 if (low == 0 || low == 1) {
16 isPrime = false;
17 }
18 else {
19 for (i = 2; i <= low / 2; ++i) {
20 if (low % i == 0) {
21 isPrime = false;
22 break;
23 }
24 }
25 }
26
27 if (isPrime)
28 cout << low << " ";
29
30 ++low;
31 }
32
33 return 0;
34}
35