-->
当前位置:首页 > 题库

PROGRAMMING:Finding the sum of formulas [1]

Luz5年前 (2021-05-10)题库374
Define the function main (), input positive integer n, calculate and output the value of the following formula. It is required to call function f (n) to calculate n * (n + 1)... (2n-1), and the return value type of function is double.
$$s=1+\frac{1}{2*3}+\frac{1}{3*4*5}+......+\frac{1}{n*(n+1)*...*(2n-1)}$$
###Input format:
The input gives a positive integer n on a line.
###Output format:
In one line, output the value s of partial sum in the format of "sum = s" to six decimal places. Please note that there is a space on the left and right of the equal sign. The calculation results should not exceed the double precision range.
###Input example:
```in
three
```
###Output example:
```out
sum = 1.183333
```







answer:If there is no answer, please comment