mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-27 08:26:20 +00:00
21 lines
308 B
C
21 lines
308 B
C
|
#include <stdio.h>
|
||
|
|
||
|
int main() {
|
||
|
int n;
|
||
|
double ans = 0;
|
||
|
|
||
|
scanf("%d", &n);
|
||
|
|
||
|
for (int i = 0; i < n; i++) {
|
||
|
if (i % 2 == 0) {
|
||
|
ans += 1.0 / (1 + 3 * i);
|
||
|
} else {
|
||
|
ans -= 1.0 / (1 + 3 * i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
printf("sum = %.3lf\n", ans);
|
||
|
|
||
|
return 0;
|
||
|
}
|