In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Write an expression* whose value* is the 8th harmonic number.
I have tried both of these:
Code:
(double)(1 + (1 / 2) + (1 / 3) + (1 / 4) + (1 / 5) + (1 / 6) + (1 / 7) + (1 / 8))
(double)1 + (1 / 2) + (1 / 3) + (1 / 4) + (1 / 5) + (1 / 6) + (1 / 7) + (1 / 8)
Both are wrong
Correct Answer that I found!
Code:
1.0+(1/2.0)+(1/3.0)+(1/4.0)+(1/5.0)+(1/6.0)+(1/7.0) + (1/8.0)