#include<stdio.h> int main() { int i,n; float sum=0; printf("请输入所需要前n项和: "); scanf("%d",&n); n=2*n; for(i=2;i<=n;i+=2) { sum=sum+1.0/i; } printf("前%d项和为:%f\n",n/2,sum); return 0; }