求最大公约数

#include

using namespace std;

int gcd(int a, int b) {

  if(b == 0) {
  return a; 
  }
  else {
  return gcd(b, a%b);
  }

}

int main() {

  int x, y;

  cout << "Enter two numbers: "; 
  cin >> x >> y;

  cout << " << x << " and " << y << " is " << gcd(x, y) << endl;

  return 0;

}
 

你可能感兴趣的:(算法,数据结构)