include stdio include math double func int double res int for res pow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <math.h>
double func(int n) {
double res = 0;
int k;
for (k = 1; k <= n; ++k) {
res += pow(-1, k) * pow(n + 1, k) / pow(n + 2, k);
}
return res;
}
int main() {
int n;
if (scanf("%d", &n) == 1) {
printf("%lf\n", func(n));
}