qfedu-c-level/day5/homework/h11.c

22 lines
474 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 请编程, 输入两个整数, 输出两个整数所有公约数。
// 例如, 输入 12 和 18 输出 1 2 3 6。
#include <stdio.h>
int main()
{
int a, b;
printf("请输入两个整数:");
scanf("%d%d", &a, &b);
int min = a < b ? a : b; // 取两个数中较小的一个
while (min)
{
if (a % min == 0 && b % min == 0)
{
printf("%d ", min);
}
min--;
}
printf("\n");
return 0;
}