用C语言计算:s=1-1/2!+2/3!+……+((-1)^(n-1))(n-1)/n!,下面的程序是我写的,可是运行错误怎么改。 10
#include<stdio.h>doublef(intn);intmain(void){inti,n,den,flag;doublesum,item;#include<...
#include<stdio.h>
double f(int n);
int main(void)
{
int i,n,den,flag;
double sum,item;
#include<stdio.h>
double f(int n);
int main(void)
{
int i,n,den,flag;
double sum,item;
printf ("enter n:");
scanf("%d",&n);
den=0;flag=-1;sum=0;
for(i=0;i<=n;i++){
item=flag*1.0*(den-1)/f(den);
sum=sum+item;
flag=-flag;
den=den+1;
}
printf("sum=%f\n",sum);
return 0;
}
double f(int n){
int i;
double f=1.0;
for(i=1;1<=n;i++)
f*=i;
return f;
} 展开
double f(int n);
int main(void)
{
int i,n,den,flag;
double sum,item;
#include<stdio.h>
double f(int n);
int main(void)
{
int i,n,den,flag;
double sum,item;
printf ("enter n:");
scanf("%d",&n);
den=0;flag=-1;sum=0;
for(i=0;i<=n;i++){
item=flag*1.0*(den-1)/f(den);
sum=sum+item;
flag=-flag;
den=den+1;
}
printf("sum=%f\n",sum);
return 0;
}
double f(int n){
int i;
double f=1.0;
for(i=1;1<=n;i++)
f*=i;
return f;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询