递归阶乘为何不对捏....
float fac(int n){
float f;
if (n<0)
{
printf ("n<0,dataerror");
}
else
if (n==0||n==1)
f=1;
else
f=fac(n-1)*n;
return f;
}
#include "stdio.h"
int main(void)
{
int n;
float y;
printf ("input an integer number:");
scanf ("%d",&n);
y=fac(n);
printf ("%d!=%10.0f\n",n,y);
}
为何这样写不对
#include "stdio.h"
int main(void)
{
float fac(int n);
int n;
float y;
printf ("input an integer number:");
scanf ("%d",&n);
y=fac(n);
printf ("%d!=%10.0f\n",n,y);
}
float fac(int n)
{
float f;
if (n<0)
{
printf ("n<0,dataerror");
}
else
if (n==0||n==1)
f=1;
else
f=fac(n-1)*n;
return f;
}
这样写就对了
---------------------------------------------------------------------------------------
这个程序这样写是对的
int age(int n)
{
int c;
if (n==1)
c=10;
else
c=age(n-1)+2;
return c;
}
#include "stdio.h"
int main(void)
{
printf ("%d",age(5));
}
这样写也是对的
#include "stdio.h"
int main(void)
{
int age(int n);
printf ("%d",age(5));
}
int age(int n)
{
int c;
if (n==1)
c=10;
else
c=age(n-1)+2;
return c;
}
弄不明白了....