1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00
202401-programming-assignments/【实践课内】6.循环结构3/7-4 循环-分数矩阵.c

35 lines
644 B
C
Raw Normal View History

2024-11-01 08:36:33 +00:00
#include <math.h>
#include <stdio.h>
int main() {
int n;
while (scanf("%d", &n) != EOF, n != 0) {
double ans = n;
for (int i = 2; i <= n; i++) {
ans += (double)(n * 2 - 2 * (i - 1)) / (double)i;
}
/*
for (int i = 1; i <= n; i++) {
// 对角线左侧
for (int j = i; j >= 2; j--) {
ans += 1.0 / j;
}
ans += 1;
// 对角线右侧
for (int j = 2; j <= n - i + 1; j++) {
ans += 1.0 / j;
}
}
*/
printf("%.2lf\n", ans);
}
return 0;
}