-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
greatest coomon factor.txt
52 lines (39 loc) · 1.01 KB
/
greatest coomon factor.txt
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
Table of contents
1)__gcd stl
2)making a function
-------------------------------------
C++ inbuilt function for finding GCD
In many competitive programming problems, we need to find greatest common divisor also known as gcd. Euclids algorithm to find gcd has been discussed here
C++ has the built-in function for calculating GCD. This function is present in header file.
Syntax:
__gcd(m, n)
Parameter : m, n
Return Value : 0 if both m and n are zero,
else gcd of m and n.
filter_none
edit
play_arrow
**************************************************************
A*B = gcd(A,B) * lcm(A,B)
*************************************************************
1)
int main()
{
cout << "gcd(6, 20) = " << __gcd(6, 20) << endl;
}
output;
gcd(6, 20) = 2
-----------------------------------
2)
int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
int a = 98, b = 56;
cout<<"GCD "<<gcd(a, b);
return 0;
}