#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include<stdlib.h>
int main()
{
int a;
int b;
int t;
printf("请输入两个数求它们的公约数:");
scanf("%d %d", &a, &b);
if (a < b)
{
t = a;
a = b;
b = t;
}
while (a%b != 0) //反复取余,并把取余所得的值赋给较小的数
{
t = a % b;
a = b;
b = t;
}
printf("这两个数的最大公约数为%d\n", b);
system("pause");
return 0;
}
求两个数的最大公约数(辗转相除法)
猜你喜欢
转载自blog.csdn.net/qq_44828389/article/details/100610876
今日推荐
周排行