跪求一个递归计算n得阶乘!急!!

来源:百度知道 编辑:UC知道 时间:2024/07/07 01:22:18
在线等!!
我要JAVA版本的谢谢!!加分啊 别再出现C版本的了 !!

一群为分精尽人亡的人啊,同情ING
我这两天加了1000多分,还有好多帖没结,真想给点你们

JAVA和C++的语法规则大致一样,递归的函数就是这个,你在要调用的地方调用就可以了

int fact(int n) //求N的阶乘
{
int result;
if (n == 1) return 1;
result = fact(n-1) * n;
return result;
}

pcrazyc,向你学习啊!高手

C++ 计算阶乘
#include "stdafx.h"
#include"iostream.h"

long f(long n)
{
if(n<1)
{
cout<<"error";
return 0;
}
if(n==1) return 1;
else return n*f(n-1);
}

int main()
{ long a=0;
cout<<"输入:"<<endl;
cin>>a;
cout<<f(a);
return 0;
}

多少分呀!这么多人抢。 wo lai ye.
if (n==0) return 1;
return fun(n-1)*n;

#include<stdio.h>
int fun(int n)
{int s;
fun(1)=1;
while(i>1) s=fun(n-1)*n;
return s;}
int main()
{
int i;
scanf("%d",&i); <