求1+1/3+1/5+1/7+....+1/(2*n-1)
时间: 2023-11-21 15:05:28 浏览: 136
C++完成1-1/3+1/5-1/7..........
以下是求1+1/3+1/5+1/7+....+1/(2*n-1)的方法:
```c
#include <stdio.h>
float sum(int n);
int main() {
int n;
printf("请输入n的值:");
scanf("%d", &n);
printf("1+1/3+1/5+1/7+....+1/(2*n-1)=%f\n", sum(n));
return 0;
}
float sum(int n) {
float s = 0;
int i;
for (i = 1; i <= n; i++) {
s += 1.0 / (2 * i - 1);
}
return s;
}
```
阅读全文