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
#include <iostream> using namespace std; int main() { int a,b,x,y; cin >> a; cin >> b; x=a; y=b; do { if(x > y) { x -= y; } else { y -= x; } }while(y); cout << "The gcd of " << a << " and " << b << " is " << x << "." << endl; return 0; }