Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 04 / Solutions_10-14 / task12.cpp
blob: 464b17be5d867dd0763768a116cfc82e67a628f8 (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
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;

int gcd(int x, int y)
{
	while (x != y)
		if (x > y)
			x -= y;
		else
			y -= x;
	return x;
}

int main()
{
	int a, b, c, d;

	cout << "a, b, c, d= ";
	cin >> a >> b >> c >> d;
	if (!cin || a < 1 || b < 1 || c < 1 || d < 1)
	{
		cout << "Error! \n";
		return 1;
	}

	int r = gcd(a, b);
	cout << "gcd{" << a << ", " << b << "}= " << r << "\n";

	int s = gcd(c, d);
	cout << "gcd{" << c << ", " << d << "}= " << s << "\n";

	cout << "gcd{" << a << ", " << b << ", " << c << ", " << d << "}= " << gcd(r, s) << "\n";

	return 0;
}