2种方法 不解释.

#include <iostream>

using namespace std;

int main(void)

{

int a,b;

cin>>a>>b;

while(b!=0)

{

int temp=b;

b=a%b;

a=temp;

cout<<a<<endl;

return 0;

}

============================================

#include <iostream>

using namespace std;

 

int fun(int a,int b)

{

if(b==0) return a;

else return fun(b,a%b);

}

int main(void)

{

int a,b;

cin>>a>>b;

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

}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐