C语言编程,输入1个正实数eps,计算并输出下式的值,直到最后一项的绝对值小于eps。
2个回答
展开全部
#include<stdio.h>
#include<math.h>
int main()
{
double esp;
double s=0.00;
double tmp = 1.0;
int i=1, m=1;
printf("Inputeps:");
scanf("%lf", &esp);
while(fabs(tmp)>esp) {
tmp = 1.00/i;
s += (m*tmp);
i +=4;
m *= -1;
}
printf("S = %lf\n", s);
return 0;
}
展开全部
int main(int argc, _TCHAR* argv[])
{
double res=0,input = 0.00001,tem;
tem = 1;
for( int n=1; tem>=input ;n++)
{
if(n%2 ==0)
res -= tem;
else
res += tem;
tem = 1.0/(4*n+1);
}
printf("%lf",res);
getchar();
return 0;
{
double res=0,input = 0.00001,tem;
tem = 1;
for( int n=1; tem>=input ;n++)
{
if(n%2 ==0)
res -= tem;
else
res += tem;
tem = 1.0/(4*n+1);
}
printf("%lf",res);
getchar();
return 0;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询