We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c4177b0 commit f0316f3Copy full SHA for f0316f3
math/C++/prime number.cpp
@@ -0,0 +1,26 @@
1
+#include <iostream>
2
+using namespace std;
3
+
4
+int 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
+}
0 commit comments