请会C语言的人帮忙写个程序

来源:百度知道 编辑:UC知道 时间:2024/06/03 15:51:58
Here is a problem of ACM.
Input:
The input will be an integer.
Output:
The output will be an integer too.
Detail:
If the input is 1, then output is 1.
If the input is 2, then output is 2.
If the input is 3, then output is 6.
If the input is 4, then output is 42.
If the input is 5, then output is 1806.
...
Sample input:
5
Sample output:
1806
Please sovle the problem using C or C++.
朋友门,这个题目的数学规律我是知道的,我想要的是程序,麻烦大家把程序写给我,谢谢

C语言编写的一个简单实现

#include <stdio.h>
#include <conio.h>
main()
{ int i,a;
long int mout=1;

printf("请输入一个整数");

scanf("%d",&a);
while(a<=0)
{ printf("输入错误,请重新输入");
scanf("%d",&a);
}
for(i=2;i<=a;i++)
{
mout=mout*(mout+1);

}
printf("%d: %ld\n",a,mout);

getch();
}

这个问题最主要出的是找出规律
程序并不难
规律如下:
innumber
读输入的值 innumber
如果 innumber==1
结果为1
否则如果innumber>1
结果为:((innumber-1)的结果+1)*(innumber-1)的结果

计算结果的过程可以用一个递归函数来实现

#include "iostream"
using namespace std;

long fun(int a)
{
if(a==1) return 1;
else
return(fun(a-1)*(fun(a-1)+1));
}
int main()
{
int a;