我刚学习C++,不知之一串代码错误在什么地方?
#include<math.h>
#include<stdio.h>
void main()
{
float sum=1,i=3,k=-1;
while(fabs(1/i)>=0.000000001)
{
sum=sum+k*(1.0/i);
i=i+2;
k=k*-1;
}
sum=sum*4;
printf("sum=%.4f",sum);
}
#include<math.h>
#include<stdio.h>
void main()
{
float sum=1,i=3,k=-1;
while(fabs(1/i)>=0.000000001)
{
sum=sum+k*(1.0/i);
i=i+2;
k=k*-1;
}
sum=sum*4;
printf("sum=%.4f",sum);
}
2017-04-21
举报