-
-
Save FreeFly19/f985d1a81318db323349 to your computer and use it in GitHub Desktop.
Алгоритм Евкліда 4-x чисел
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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