c语言中辗转相除求最大公约数·
时间: 2024-05-23 13:15:36 浏览: 91
C语言程序设计-用辗转相除法求两个整数的最大公约数;.c
5星 · 资源好评率100%
#include <stdio.h>
int gcd(int a, int b)
{
int r;
while(b != 0)
{
r = a % b;
a = b;
b = r;
}
return a;
}
int main()
{
int a, b, result;
printf("Enter two integers: ");
scanf("%d%d", &a, &b);
result = gcd(a, b);
printf("The GCD of %d and %d is %d\n", a, b, result);
return 0;
}
阅读全文