forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPRIME NUMBERS BETWEEN TWO INTERVALS
50 lines (24 loc) · 1.04 KB
/
PRIME NUMBERS BETWEEN TWO INTERVALS
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int n1,n2,p;
cout<<"Enter the range to print the prime numbers:\n";
cin>>n1>>n2;
for(int i=n1;i<=n2;i++) //loop will run from first number till last number
{
p=1; /*by default we'll take value as 1 and when the next loop will start then it'll turn this value as 0 while violating the condition of being a prime number*/
for(int j=2;j<=i/2;j++) /*this loop will run from 2 as to check that the number is not getting divided by any natural number(condition of prime number)*/
{
if(i%j==0) /*this is checking that the number is not getting divided by any natural number*/
{
p=0; /*p=0 when the number is divided by other natural numbers(violation of condition of prime number)*/
break;
}
}
if(p==1)
cout<<i<<", ";
}
return 0;
}