This problem no difficulty, but need to pay attention to the decimal division, the dividend should be rewritten 1.0 instead of 1, when either integer result.
#include<stdio.h> #include<math.h> #define f(n) n*n+n+41 int main(void) { int m; scanf("%d",&m); while(m>0) { int n; scanf("%d",&n); double sum=0; int flag=1; double temp=1; int i; for(i=1;i<=n;i++) { temp=flag*(1.0/i); sum=sum+temp; flag=-flag; } m--; printf("%0.2f\n",sum); } return 0; }