有如下表达式s=1+1/3+(1×2)/(3×5)+(1×2×3)/(3×5×7)+……+(1×2×3×……×n)/(3×5×7×……×(2×n+1))。编写函数求给出的n所对应的表达式s的值。
int f(int n) {
int top = 1;
for (int i = 1; i <= n; i++) {
top *= n;
}
int bottom = 1;
for (int i = 1; i <= 2*n + 1; i +=2) {
bottom *= i;
}
printf("%d", top / bottom);
}
用循环吧,分子是阶乘,分母奇数相乘