#include<stdio.h>
int gcd_rec(int, int);
int gcd_loop(int, int);
int main(void)
{
int x,y;
printf("Please input 2 int\n");
scanf("%d %d",&x, &y);
printf("gcd_rec:%d\n",(gcd_rec(x, y)));
printf("gcd_loop:%d\n",(gcd_loop(x, y)));
return 0;
}
int gcd_rec(int a, int b)
{
if((a%b)==0)
return b;
else
return(gcd_rec(b,a%b));
}
int gcd_loop(int a, int b)
{
int c;
while(1)
{
if((c=(a%b))==0)
break;
else
{
a=b;
b=c;
}
}
return b;
}
全站熱搜
留言列表