-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisItPrimeNumber.cpp
More file actions
35 lines (31 loc) · 884 Bytes
/
Copy pathisItPrimeNumber.cpp
File metadata and controls
35 lines (31 loc) · 884 Bytes
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
//Algorithm for checking if given number is even or odd for c++ language
#include <iostream>
using namespace std;
////////////////////ready function
void isItPrime(int n)
{
if(n == 0)
cout << "This is NOT prime number (0)";
else if(n == 1)
cout << "This is NOT prime number (1)";
else
{
for(int x = 2; x < n; x++)
{
if(n % x == 0) //every time it finds a divisor the program stops and gives answer
{
cout << "This is NOT prime number (" << n << ")";
break;
}
if(x == n-1) //if program did not found divisors it means the number is prime number
cout << "This IS prime number (" << n << ")";
}
}
}
////////////////////
int main()
{
int a = 1121; //number that is checked
isItPrime(a); //using function
return 0;
}