考虑到运行效率,选择辗转相除法进行求最大公约数。
代码如下:
#include<stdio.h>
int main(void)
{
int a,b,temp;
scanf("%d %d",&a,&b);
if(b>a){
temp=a;
a=b;
b=temp;
}
while(b>0)
{
temp=a%b;
a=b;
b=temp;
}
printf("%d",a);
}
京公网安备 11010502036488号