# 很简单的一道题

输入n(1<=n<=10)，输入-1程序终止。

输出f(n)的结果（保留30位小数）

``````1
3
6
10
-1``````

``````1.000000000000000000000000000000
0.166666666666666666666666666666
0.047619047619047619047619047619
0.018181818181818181818181818181``````

``````#include"stdio.h"
int main()
{
int n,i,j,a[30],yu,shang,m;
while(scanf("%d",&n)!=EOF && n!=-1)
{
if(n%2==0)
{
m=0;
for(j=1;j<=n;j++)
m=m+j;
}
else
{
m=1;
for(j=1;j<=n;j++)
m=m*j;

}
shang=1/m;
yu=1%m;
for(i=1;i<=30;i++)
{
yu=yu*10;
a[i]=yu/m;
yu=yu%m;
}
printf("%d.",shang);
for(i=1;i<=30;i++)
printf("%d",a[i]);
printf("\n");
}
return 0;
}
``````

``````#include <iostream>
#include <stdio.h>
using namespace std;
int sum(int);
int chen(int);
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==-1)
break;
int  p,c=1;
//double b;
if(n%2==0)
p=sum(n);
else
p=chen(n);
// b=1/((double)p);
//   printf("%.30lf\n",b);
if(n==1)
cout<<"1.000000000000000000000000000000\n";
else
{
cout<<"0.";
for(int i=0;i<30;i++)
{
c*=10;
cout<<(c/p);
c=(c%p);

}
cout<<endl;

}
}
return 0;
}
int sum(int a)
{
if(a==0)
return 0;
else
return(a+sum(a-1));
}
int chen(int a)
{
if(a==1)
return 1;
else
return (a*chen(a-1));
}
``````