菜鸟上路,求好人解答不懂
代码如下:#include<stdio.h>
#include<math.h>
int main()
{
int denominator,flag,n,i;
double item,sum;
scanf("%d",&n);
denominator=1;
flag=1;
sum=0;
for(i=1;i<=n;i++)
{
item=flag*1.0/denominator;
sum=sum+item;
flag=-flag;
denominator=denominator+2;
}
printf("%f\n",sum);
return 0;
}
上面代码中的 item=flag*1.0/denominator;为什么改成item=flag*1/denominator;会运行输出结果错误?