#include <stdio.h>
int fun (int a,int b)
{
int c;
c=a%b;
if (c==0)
return b;
else
{
fun (b,c);
}
}
main ()
{
int x,y,i;
scanf ("%d%d",&x,&y);
if (x<0||y<0)
printf ("有负数");
else if (x<y)
{
i=fun (y,x);
printf ("%d",i);
}
else
{
i=fun (x,y);
printf ("%d",i);
}
}
此程序运用的是辗转相除法