#29256: C++ 用gcd寫


Asuna950520 (YuukiAsunaOuO)

School : 南山中學
ID : 181208
IP address : [1.169.64.49]
Last Login :
2022-06-12 20:10:48
a024. 最大公因數(GCD) | From: [1.169.74.216] | Post Date : 2022-02-09 17:28

#include <cstdlib>

#include <iostream>

int gcd(int x,int y);

using namespace std;

int main(void)

{

int a,b;

cin>>a>>b;

cout<<gcd(a,b)<<endl;

return 0;

}

int gcd(int x,int y)

{

if(x!=0&&y!=0)

{

return gcd((x>=y)?x%y:x,(x<y)?y%x:y);

}

else

{

return(x!=0)?x:y;

}

}

 
ZeroJudge Forum