We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 28d5410 commit 88dc029Copy full SHA for 88dc029
identifyPrime.cpp
@@ -0,0 +1,27 @@
1
+#include <cmath>
2
+#include <iostream>
3
+bool identifyPrime(int);
4
+
5
6
+int main() {
7
+ int num;
8
+ std::cout << "Enter a number: "; std::cin >> num;
9
+ if (identifyPrime(num))
10
+ std::cout << std::endl << num << " is a prime number";
11
+ else
12
+ std::cout << std::endl << num << " is not a prime number";
13
+ return 0;
14
+}
15
16
17
+bool identifyPrime(int a) {
18
+ bool isPrime = true;
19
+ float sqrt_a = sqrt(a);
20
+ for (int i = 2; i < sqrt_a; i++) {
21
+ if (a%i == 0) {
22
+ isPrime = false;
23
+ break;
24
+ }
25
26
+ return isPrime;
27
0 commit comments