[圖解C] ex 5-8

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num1, num2, large, small, temp, remain=1, ans=1;
   
    printf("enter 1st value: ");
    scanf("%d", &num1);
    printf("enter 2nd value: ");
    scanf("%d", &num2);
   
    large = num1;
    small = num2;
   
    while (remain != 0)
    {  
        if (large < small)
        {
            temp = large;
            large = small;
            small = temp;
        }
       
        ans = remain;
        remain = large % small;
        large = remain;
    }
   
    printf("the gcd is %d\n", ans);
   
    system("pause");
    return 0;
}