*最大公因數

 avatar
user_6817964
c_cpp
2 years ago
364 B
3
Indexable
Never
#include <stdio.h> // printf
int main()
{
    int a, b, max, last = 1;
    scanf_s("%d%d", &a, &b);
    if (a > b)
        max = a;
    else
        max = b;
    printf("1");
    for (int i = 2; i <= max; i++) {
        if (a % i == 0 && b % i == 0) {
            printf(" %d", i);
            last = i;
        }
    }
    printf("\n%d", last);
}