Skip to content

Instantly share code, notes, and snippets.

@s-melnikov
Created March 21, 2019 19:51
Show Gist options
  • Save s-melnikov/571e2a3fd580c431b859e2003c11f1cd to your computer and use it in GitHub Desktop.
Save s-melnikov/571e2a3fd580c431b859e2003c11f1cd to your computer and use it in GitHub Desktop.
Greatest common divider
#include <iostream>
using namespace std;
int gcd(int a, int b) {
while (a != b) {
if (a > b) {
a = a - b;
} else {
b = b - a;
}
}
return a;
}
int main() {
int a, b;
cout << "a = ";
cin >> a;
cout << "b = ";
cin >> b;
cout << "GCD ( " << a << ", " << b << " ) = " << gcd(a, b) << endl;
system("pause >> void");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment