#include<stdio.h> int main() { int i = 0; int n; double sum = 0.0, sign = 1; int flag = 1; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) { sign = (flag * 1.0) / i; sum += sign; flag = -flag; } printf("%.3lf\n", sum); } return 0; }
#include<stdio.h> int main() { int i = 0; int n; double sum = 0.0, sign = 1; int flag = 1; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) { sign = (flag * 1.0) / i; sum += sign; flag = -flag; } printf("%.3lf\n", sum); } return 0; }