下面是使用C语言来计算最大公约数的事例代码。
/* Program to find the greatest common divisor of two nonnegative integer values */
#include <stdio.h>
int main(void)
{
int u, v, temp;
printf("Please type in two nonnegative integers.\n");
scanf("%i%i", &u, &v);
while(v!=0)
{
temp = u % v;
u = v;
v = temp;
}
printf("Their greatest common divisor is %i\n", u);
return 0;
}

本文提供了一个使用C语言编写的简单程序示例,该程序能够接收两个非负整数作为输入,并通过辗转相除法计算这两个数的最大公约数。
4690

被折叠的 条评论
为什么被折叠?



