大家来帮一下C语言菜鸟!
求 1-1/2+1/3-1/4...............-1/100的值?我自己写的,但得不到答案,请指出错误,谢谢!
#include<stdio.h>
main()
{
int a,i,sim;
float sum;
sum=1;
for(a=2;a<=100;a++)
{
sim=1;
sim=sim*(-1);
i=sim*(1/a);
sum=sum+i;
}
printf("sum=%f",sum);
printf("\n");
}