-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec24_Basicmath.cpp
99 lines (72 loc) · 1.22 KB
/
lec24_Basicmath.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//Prime no.
/*
#include<iostream>
using namespace std;
bool isPrime(int n) {
if(n<=1)
return false;
for(int i=2; i<n; i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
int countprime(int n)
{
int cnt=0;
vector<int> prime(n+1,true);
prime[0]=prime[1]=false;
for(int i =2;i<n;i++)
{
if(prime[i])
{
cnt++;
for(int j=2*i;j<n;j+=i)
{
prime[j]=0;
}
}
}
return cnt;
}
int main() {
int n;
cin >> n;
if(isPrime(n)) {
cout << "It is a Prime Number" << endl;
}
else{
cout << " It is not a Prime Number" << endl;
}
return 0;
}
*/
#include<iostream>
using namespace std;
int gcd(int a, int b) {
if(a==0)
return b;
if(b==0)
return a;
while(a != b) {
if(a>b)
{
a = a-b;
}
else{
b = b-a;
}
}
return a;
}
int main() {
int a,b;
cout << "Enter the Values of a and b" << endl;
cin >> a >> b;
int ans = gcd(a,b);
cout << " The GCD of " << a << " & " << b << " is: " << ans << endl;
return 0;
}