#include <stdio.h>void main() {int x;int fm = 0;//分母double sum = 0;printf("请输入一个正整数:");scanf("%d", &x);for (int i = 1; i <= x; i++) {fm += i;//分母变化sum = sum + 1.0 / fm;if (i != x) {printf("1/%d + ", fm);} else {printf("1/%d = ", fm);}}printf("%lf", sum);
}
运行结果:
本章C语言经典例题合集:http://t.csdnimg.cn/FK0Qg