-
Notifications
You must be signed in to change notification settings - Fork 0
/
WSQ12.cpp
63 lines (50 loc) · 765 Bytes
/
WSQ12.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
// The following program calculates the Greatest Common Division between two integers.
#include <iostream>
#include <cstdlib>
using namespace std;
int gcd(int a, int b)
{
int gcd;
if(a == b)
{
return a;
}
if (a < b)
{
int temp;
temp = a;
a = b;
b = temp;
}
int rem = a%b;
if (rem == 0)
{
return b;
}
while ( rem >= 1)
{
rem = a % b;
if (rem == 0)
{
return b;
}
a = b;
b = rem;
gcd = b;
}
return gcd;
}
int main ()
{
int a;
int b;
cout << "This is a GCD calculator: " << endl;
cout << endl;
cout << "Enter the first value:" << endl;
cin >> a;
cout << "Enter the second value:" << endl;
cin >> b;
cout << endl;
cout << "The GCD of " << a << " and " << b << " is: " << gcd(a,b) << endl;
return 0;
}