最大公约数-递归

#include<iostream>
#include<climits>
using namespace std;

int gcd(int x, int y) {
  if (x==y) {
    return x;
  }
  else if (x>y) {
    return gcd(y, x-y);
  }
  else if (x<y) {
    return gcd(x, y-x);
  }
}

int main(){
  int a,b;
  cin>>a>>b;
  cout<<gcd(a,b);
  return 0;
}

posted @ 2021-12-30 11:23  Hi,小董先生  阅读(45)  评论(0)    收藏  举报