Skip to content

Commit f68994f

Browse files
authored
Merge pull request #1945 from Prabsimar-singh/patch-2
SolutionByPrabsimar.cpp
2 parents a5cbba2 + a3d3b23 commit f68994f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//PRIME OR NOT
2+
3+
#include <cmath>
4+
#include <iostream>
5+
using namespace std;
6+
int main(int argc, char const* argv[])
7+
{
8+
int n;
9+
cout << "Enter a number: "<<endl;
10+
cin >> n;
11+
if (n <= 0) {
12+
cout << "Kindly Enter Natural Numbers"<<endl;
13+
} else if (n == 1) {
14+
cout << "1 is neither Prime nor Composite"<<endl;
15+
} else {
16+
for (int i = 2; i <= sqrt(n); i++) {
17+
if (n % i == 0) {
18+
cout << n << " is not a prime Number";
19+
exit(0);
20+
}
21+
}
22+
cout << n << " is a prime Number"<<endl;
23+
}
24+
return 0;
25+
}

0 commit comments

Comments
 (0)