菜鸟自己写的求最大公约数的算法(不同于辗转相减法)
#include <stdio.h>int main()
{
int num1 = 0;
int num2 = 0;
int i = 0;
int temp = 0;
int fac = 0;
printf("Please input an integer:\n");
while (scanf("%d%d",&num1,&num2) != EOF)
{
fac = 1;
if (num1<num2)
{
temp = num1;
num1 = num2;
num2 = temp;
}
for (i=2; i<num2+1; i++)
{
while (1)
{
if (num1%i==0 && num2%i==0)
{
num1 = num1/i;
num2 = num2/i;
fac *= i;
}
else
{
break;
}
}
}
printf("%d\n",fac);
}
return 0;
}