1.使用辗转相除法
2.输出结果
#include<iostream>
using namespace std;
int g(int a,int b){
if(a<b){swap(a,b);}
int t=1;
while(t){
t=a%b;
a=b;
b=t;
}
return a;
}
int main(){
int num;
printf("请输入两个正整数:");
int a,b;
cin>>a>>b;
printf("最大公约数为%d",g(a,b));
return 0;
}
标签:return,int,31,最大公约数,printf,day From: https://www.cnblogs.com/drz1145141919810/p/17411649.html