求帮看递归代码,实在改不对了
是我的static错了吗
题目:【题目描述】
从键盘任意输入两个正整数,求这两个数的最大公约数。要求使用递归的方法完成。
【输入样例】
24 36
【输出样例】
12
#include<stdio.h>
//使用递归方法完成求最大公约数
unsigned GetGreatestCommonDivisor(unsigned int x,unsigned int y);
int main()
{
unsigned int x,y,z;
scanf("%u %u",&x,&y);//输入语句
z=GetGreatestCommonDivisor(x,y);
printf("%u",z);//输出语句
return(0);
}
unsigned GetGreatestCommonDivisor(unsigned int x,unsigned int y)
{
static int i;
i=(x>y?y:x);
if(y!=x)
{
if(y%i==0&&x%i==0)
{
return (i);
}
else
{
i--;
return GetGreatestCommonDivisor(x,y);
}
}
else
return x;
}