#include <iostream>
using namespace std;
int gcd(int x, int y);
int main()
{
const int SENTINEL = -1;
cout << "Enter 2 integers, the program will find the GCD(x,y)\n"
<< "Using " << SENTINEL << " to exit." << endl;
int x, y;
while (true) {
cout << "?";
cin >> x;
if (x == SENTINEL) break;
cin >> y;
cout << "GCD == " << gcd(x, y) << endl;
}
return 0;
}
int gcd(int x, int y) {
if (x % y == 0) return y;
return gcd(y, x%y);
}
stanford cs106b GCD(x, y) demo
最新推荐文章于 2024-03-27 21:14:23 发布