#include <stdio.h>
int maxog(int m, int n)
{
int r = 0, k, j;
if(m == n)
return n;
(m - n > 0) ? (k = m, j = n) : (k = n, j = m);
r = k % j;
//如果此处刚好能够整除,说明j就是最大公因子,
printf("%d %c %d = %d\n",k,0x25,j,r);
//0x25用于输出取模%符,直接在格式字符里写 %无法输出!!!
while(r != 0)
{
k = j;
j = r;
r = k % j;
//使用辗除法求最大公因子!!!
printf("%d %c %d = %d\n",k,0x25,j,r);
}
return (j);
//如果能够整除,除数j就是最大公因之
}
int main(void)
{
int m, n, i = 0, k = 0 , j = 0;
printf("input 2 number :\n");
scanf("%d%d",&m,&n);
if(m <= 0 || n <= 0)
{
printf("input error!");
return -1;
}
else
{
n = maxog(m,n);
printf("common factor is :%d\n",n);
}
return 0;
}