c语言用函数编写:1-1/2+1/3-1/4.....+((-1)^(n+1))*(1/n)
#include<stdio.h>doublefun(intn);main(){intx;printf("Pleaseenterx:");scanf("%d",&x);p...
#include <stdio.h>
double fun(int n);
main()
{ int x;
printf("Please enter x:");
scanf("%d",&x);
printf("%f\n",fun(x));
}
double fun (int n)
{ int i=1,t=1;
double s=0;
while(i<=n)
{s=s+t/i;
t=-t;
i++;}
return s;
}
这个程序哪儿不对? 展开
double fun(int n);
main()
{ int x;
printf("Please enter x:");
scanf("%d",&x);
printf("%f\n",fun(x));
}
double fun (int n)
{ int i=1,t=1;
double s=0;
while(i<=n)
{s=s+t/i;
t=-t;
i++;}
return s;
}
这个程序哪儿不对? 展开
展开全部
#include <stdio.h>
double fun(int n);
main()
{ int x;
printf("Please enter x:");
scanf("%d",&x);
printf("%f\n",fun(x));
}
double fun (int n)
{ int i=1,t=1;
double s=0;
while(i<=n)
{s=s+t/i;//改成s=s+1.0*t/i;t和i都是int,所以t/i也是int
t=-t;
i++;}
return s;
}
double fun(int n);
main()
{ int x;
printf("Please enter x:");
scanf("%d",&x);
printf("%f\n",fun(x));
}
double fun (int n)
{ int i=1,t=1;
double s=0;
while(i<=n)
{s=s+t/i;//改成s=s+1.0*t/i;t和i都是int,所以t/i也是int
t=-t;
i++;}
return s;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询