首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

c入门,改错,该如何处理

2012-03-01 
c入门,改错求出1-1/3+1/5-1/7+......到10的负6次方为止#includestdio.h #includemath.h intmain(){dou

c入门,改错
求出1-1/3+1/5-1/7+......到10的负6次方为止
#include   "stdio.h "
#include   "math.h "
int   main()
{
double   a,s,t;
a=1;s=0;t=1;
whille(fabs(t)> 1e-6)
{s=s+t;a+=2;t=-1/a;
}
printf( "%f ",4s);
}

[解决办法]
double t, s = 1.0;
int a = 1,sgin = 1;

do
{
t = s;
a += 2;
if(sgin%2)
s -= 1.0/a;
else
s += 1.0/a;

sgin++;
}while(fabs(s-t)> 1.e-6);

printf( "%f ", s);

[解决办法]
还少个 return 0 ;
[解决办法]
#include "stdio.h "
#include "math.h "

//1-1/3+1/5-1/7+......
int main()
{
double a,s,t;
a=1;s=0;t=1;
while(fabs(t)> 1e-6)
{s=s+t;a+=2;t=-1/a;
}
printf( "%4f ", s);
return 0;
}

[解决办法]

s=s+t;a+=2;t=-1/a;

改为:

a+=2;t=-1/a;s=s+t;

循序不对吧,是不是这样数值就少一次了啊?


热点排行