forked from aditya109/git-osp-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.cpp
More file actions
30 lines (24 loc) · 680 Bytes
/
Copy pathPrime.cpp
File metadata and controls
30 lines (24 loc) · 680 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
#include<bits/stdc++.h>
using namespace std;
// function to check number is prime or not..
bool IsPrime(int n) {
if(n<2) return false; // if number is less than 2 then it will not prime
for(int i = 2; i<=sqrt(n); i++) //loop to check number is prime or not
{
if(n%i==0) return false; // we will check if number is divisible by any number from 2 to n/2+1, then it will not prime
}
return true;
}
int main() {
int size = 20;
int arr[size];
for(int i=0; i<size; i++) cin>>arr[i];
for(int i=0; i<size; i++)
{
if(IsPrime(arr[i]) == true)
{
cout<<arr[i]<<" "; // print the prime numbers..
}
}
return 0;
}