#include<stdio.h>#include<math.h>int main(){ double n=1; float term=1.0,sign=1,sum=0; while(fabs(n)<10e-4) { term=sign*1/n; sum=sum+term; sign=-sign; n++; } printf("sum=%f\n",sum); return 0;}
循环判断条件应该是
while (fabs(1/n) >= 1e-4)