C语言入门题库——求最大公约数

C语言入门题库——求最大公约数

Description:从键盘上输入两个数据,显示它们的最大公约数。
Input:48 24
Output:24
Sample Input:24 36
Sample Output:12

//求最大公约数
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d%d", &a, &b);
    while(b != 0)
    {
        c = a % b;
        a = b;
        b = c;
    }
    printf("%d", a);
    return 0;
}
发布了27 篇原创文章 · 获赞 0 · 访问量 962

猜你喜欢

转载自blog.csdn.net/qq_43479432/article/details/104447082