-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP40FUNCTION.cpp
More file actions
34 lines (27 loc) · 828 Bytes
/
P40FUNCTION.cpp
File metadata and controls
34 lines (27 loc) · 828 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
// prime numbers between two given numbers or intervals
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num){ // this part is basically the function
for (int i = 2; i <=sqrt(num); i++)
{
if (num%i==0)
{
return false; // it means its non prime
}
}
return true; // it means when this for loop completes ,its a prime
}
int main() {
int a,b;
cout<<"enter no.: ";
cin>>a>>b;
for (int i=a; i<=b; i++)
{
if (isPrime(i)) // here the if condition itself checks if the condition is true
{
cout<<i<<endl; // if true then prints
}
}
return 0;
}