c语言怎样编n的双阶乘

如题所述

#include <iostream>using namespace std;int jiecheng(int n){ int t=1; for (int i=1;i<=n;i++) t=t*i; return t;}void main(){ int jiecheng(int n); int n; cout<<"please input a number: "; cin>>n; cout<<"the result is : "<<jiecheng(jiecheng(n))<<endl;
}
输入3的时候答案是720相对于3的阶乘6,6的阶乘720!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-16
用递归可实现,与单阶乘一样做法
第2个回答  2013-11-16
#include<iostream.h>
int sum(int n)
{
int temp=1;
if(n%2==0)
for(int i=2;i<=n;i=i+2)
temp*=i;
else
for(int j=1;j<=n;j=j+2)
temp*=j;
return temp;
}
void main()
{
int n;
cout<<"n=";
cin>>n;
cout<<"n!!="<<sum(n)<<endl;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网