**// find the greatest common divisor gcd, 最大公约数**
#include "stdio.h"
#include <stdlib.h>
#include <time.h>
int main()
{
int higher, lower,temp_den;
int numerator, denominator, quotient, remainder;
scanf("%d %d",&higher,&lower);
if (higher > lower)
{
numerator = higher;
denominator = lower;
}
else
{
numerator = lower;
denominator = higher;
}
do
{
remainder = numerator%denominator;
temp_den = denominator;
numerator = denominator;
denominator = remainder;
} while (remainder != 0);
printf("%d与%d的最大公约数为%d",higher,lower,temp_den);
return 0;
}
求最大公约数
于 2023-04-04 17:59:37 首次发布