简单小程序——求两个数的最大公约数

求两个数的最大公约数程序如下:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a;
    int b;
    printf("请输入两个数:");
    scanf("%d%d", &a, &b);
    if (a < b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    while ((a%b)!=0)
    {
        int t = b;
        b = a%b;
        a = t;
    }
    printf("%d", b);
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ffsiwei/article/details/80217652