Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / example 2 - gcd (euclid).cpp
blob: 4f2a97d43aa68b67c6788084fc3d02ce44684cae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;

	if (n < k) //swap
	{
		int temp = k;
		n = k;
		k = temp;
	}
	
	while (k != 0)
	{
		int mod = n % k;
		n = k;
		k = mod;
	}

	cout << n << endl;
}