Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

cpusspuss

Name: Anonymous 2012-09-24 21:11

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. Assume that  n is an integer variable whose value is some positive integer N. Assume also that  hn is a  double variable whose value is the Nth harmonic number. Write an expression whose value is the (N+1)th harmonic number.

Why is the answer:
hn + 1/(n+1)
incorrect?

Name: Anonymous 2012-09-24 21:20

It is correct. hn+(1÷(n+1)) will be the value of the next harmonic number.

Name: Anonymous 2012-09-24 21:31

If n is a positive integer, 1/(n+1) can only ever be 0.

hn + 1.0 / (n + 1)

Except that 1 and 1.5 are the only harmonic numbers that can be represented exactly by a double.

Name: Anonymous 2012-09-25 1:47

(foldl (λ (n z) (+ z (/ 1.0 n))) 0 (range 1 (+ n 1)))

Name: Anonymous 2012-09-25 3:17

>>4

umean (foldl + 0 (map (λ (x) (/ 1 x)) (range 1 (+ n 1))))?

Name: Anonymous 2012-09-25 3:18

err (apply + (map (λ (x) (/ 1 x)) (range 1 (+ n 1))))

Name: Anonymous 2012-09-25 4:57

J:
harmonic =: (+/ @: % @ (1+i.))"0

Name: Anonymous 2012-09-25 7:06

>>3
Use a better language than C

Name: Anonymous 2012-09-25 9:57

h = (scanl((.(1/)).(+))1[2..]!!)

Don't change these.
Name: Email:
Entire Thread Thread List