递归的一道题 帮忙看看哪错了
#include"stdio.h"int gcd(int m,int n)
{
int r;
if(m%n==0) return n;
else if(m%n==r)
{
if(r>0)
return gcd(n,r);
}
}
main()
{
int a,b;
printf("int two numberds:");
scanf("%d%d",&a,&b);
printf("%d",gcd(a,b));
}
求两个数的最大公约数

程序代码:#include <stdio.h>
int MaxCommonFactor(int a,int b);
main()
{
int a,b,c=0;
printf("Input a,b:");
scanf("%d,%d",&a,&b);
c=MaxCommonFactor(a,b);
printf("the result is:%d",c);
}
int MaxCommonFactor(int x,int y)
{
if(x>y)
{
MaxCommonFactor(x-y,y);
}
else if(x<y)
{
MaxCommonFactor(x,y-x);
}
else
{
return x;
}
}
这个是碾转相除法求最大公约数,用的也是递归
程序代码:#include<stdio.h>
int MaxCommon(int ,int);
int main()
{
puts("Input 2 integers:");
int m,n;
scanf("%d%d",&m,&n);
int k = MaxCommon(m,n);
printf("%d和%d的最大公约数是%d\n",m,n,k);
return 0;
}
int MaxCommon(int m,int n)
{
int k;
for(k = m < n ? m : n;n % k != 0||m % k != 0;k--);
return k;
}