如何用C语言编写任意数的阶乘

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:13:32
如何用C语言编写任意数的阶乘
是大1的题,
要用 FOR语句和IF语句
不是要用数组莫?

/*源程序: */
fac(int n)
{int t;
if(n==1)||(n==0) return 1;
else
{ t=n*fac(n-1);
return t;
}
}
main( )
{int m,y;
printf(“Enter m:”);
scanf(“%d”,&m);
if(m<0) printf(“Input data Error!\n”);
else
{y=fac(m);
printf(“\n%d! =%d \n”,m,y);
}
}

pascal编的行不行?

#include
int main()
{
int fac(int n);
int s=0,n;
cin>>n;
for(int i=1;i<=n;i++)
{
s=s+fac(i);
}
for(i=1;i<=n;i++)//控制输出
{
cout<< if(i==n)
break;
for(int j=1;j<=1;j++)
cout<<"+";
}
cout<<"=&qu