Skip to content

Instantly share code, notes, and snippets.

/C++

Created February 28, 2016 12:12
Show Gist options
  • Save anonymous/4c9241212bad6c915ae0 to your computer and use it in GitHub Desktop.
Save anonymous/4c9241212bad6c915ae0 to your computer and use it in GitHub Desktop.
Алгоритм Евкліда 4-x чисел
// Флгоритм Евкліда.cpp: главный файл проекта.
#include "stdafx.h"
#include <iostream>
using namespace std;
int NOD(int a, int b)
{
if (a == 0){ return b; }
else
{
while ((b != a) && (b != 0))
{
a > b ? a -= b : 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