-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathINS_P1.CPP
More file actions
60 lines (55 loc) · 870 Bytes
/
Copy pathINS_P1.CPP
File metadata and controls
60 lines (55 loc) · 870 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//INS P1
/**
*
* @author Raj Dhanani
*/
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
int isPrime(int x){
int flag = 1;
for(int i = 2 ;i < x; i++){
if(x % i == 0){
flag = 0;
}
}
return flag;
}
int nthPrime(int n){
int j=0,prev = 2;
for(int count = 1; count <= n ; count++){
while(1){
if(isPrime(prev)){
j = prev;
prev++;
break;
}
prev++;
}
}
return j;
}
int GCD(int a,int b){
int min = (a<b)?a:b;
for(int c = min ; c > 1; c--){
if(a%c == 0 && b%c == 0){
return c;
}
}
return 1;
}
int main(){
clrscr();
cout<<"Enter 2 numbers:\n";
int a,b,n1,n2;
cin>>a>>b;
cout<<"GCD:"<<GCD(a,b);
cout<<"Enter range for primes:\n";
cin>>n1>>n2;
cout<<"PRIMES ARE:";
for(int i = n1 ; i <= n2; i++){
cout<<nthPrime(i)<<"\n";
}
getch();
return 0;
}