AC代码:
#include <iostream> #include <cstdio> int main(void) { freopen("in.txt","r",stdin); int m; scanf("%d",&m); while(m--) { int n; scanf("%d",&n); double sum = 0,t=1,x; int k=1; for(int i=1;i<=n;i++) { x=1/t; x=k*x; sum+=x; t++; k=(-1)*k; } printf("%.2lf ",sum); } fclose(stdin); return 0; }