#include
#include
int factorial(int n);
double fact(int n);
double power(int n);
int main()
{
int i,j;
double ff=0;
double mm;
printf("Input a integer:");
scanf("%d",&i);
mm = fact(i);
printf("%f\n",mm);
for(j=1;j<=i;j++)
{
ff+=power(j)*fact(j);
}
printf("%0.4f\n",ff);
return 0;
}
int factorial(int n)
{
if(n==0||n==1)
return 1;
else
return n*factorial(n-1);
}
double fact(int n)
{
double result,f;
char s[20];
f = factorial(n);
result = 1/f ;
sprintf(s,"%0.4f",result);
result = atof(s);
return result;
}
double power(int n)
{
int i;
double result=-1;
for(i=0;i
result*=-1;
}
return result;
}
我建议是最后的计算结果保留4为小数,要不计算结果不精确。