Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Forked from anonymous/C++
Last active February 28, 2016 12:16
Show Gist options
  • Save FreeFly19/f985d1a81318db323349 to your computer and use it in GitHub Desktop.
Save FreeFly19/f985d1a81318db323349 to your computer and use it in GitHub Desktop.
Алгоритм Евкліда 4-x чисел
#include "stdafx.h"
#include <iostream>
using namespace std;
int NOD(int a, int b) {
if (a == 0) {
return b;
}
while ((b != a) && (b != 0)) {
if (a > b) {
a -= b;
} else {
b -= a;
}
}
return a;
}
int main() {
int a, b, c, d, firstNod, secondNod;
cout << "A=";
cin >> a;
cout << "B=";
cin >> b;
cout << "C=";
cin >> c;
cout << "D=";
cin >> d;
firstNod = NOD(a, b);
cout << "First NOD=" << firstNod << endl;
secondNod = NOD(c, d);
cout << "Second NOD=" << secondNod << endl;
cout << "Absolute NOD=" << NOD(firstNod, secondNod) << endl;
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment