qfedu-c-level/day6/homework/h6.c

26 lines
618 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.

// 编写程序并设计函数, 接收两个整数参数,输出这两个整数的所有公约数。 【提示】在main函数中通过键盘输入两个整数并调用设计的函数。
#include <stdio.h>
void commonDivisors(int numA, int numB);
int main()
{
int a, b;
printf("请输入两个整数: ");
scanf("%d %d", &a, &b);
commonDivisors(a, b);
return 0;
}
void commonDivisors(int numA, int numB)
{
int min = numA < numB ? numA : numB;
while (min)
{
if (numA % min == 0 && numB % min == 0)
printf("%d ", min);
min--;
}
printf("\n");
}