Harmonic series: Difference between revisions

(Add COBOL)
Line 1,572:
4,550th iteration of the harmonic series, the sum is greater than 9
12,367th iteration of the harmonic series, the sum is greater than 10
</pre>
 
=={{header|Ring}}==
<lang ring>
decimals(12)
sum = 0
nNew = 1
limit = 13000
Harmonic = []
 
 
for n = 1 to limit
sum += 1/n
add(Harmonic,[n,sum])
next
 
see "The first twenty harmonic numbers are:" + nl
for n = 1 to 20
see "" + Harmonic[n][1] + " -> " + Harmonic[n][2] + nl
next
see nl
 
for m = 1 to 10
for n = nNew to len(Harmonic)
if Harmonic[n][2] > m
see "The first harmonic number greater than "
see "" + m + " is " + Harmonic[n][2] + ", at position " + n + nl
nNew = n
exit
ok
next
next
</lang>
{{out}}
<pre>
The first twenty harmonic numbers are:
1 -> 1
2 -> 1.500000000000
3 -> 1.833333333333
4 -> 2.083333333333
5 -> 2.283333333333
6 -> 2.450000000000
7 -> 2.592857142857
8 -> 2.717857142857
9 -> 2.828968253968
10 -> 2.928968253968
11 -> 3.019877344877
12 -> 3.103210678211
13 -> 3.180133755134
14 -> 3.251562326562
15 -> 3.318228993229
16 -> 3.380728993229
17 -> 3.439552522641
18 -> 3.495108078196
19 -> 3.547739657144
20 -> 3.597739657144
 
The first harmonic number greater than 1 is 1.500000000000, at position 2
The first harmonic number greater than 2 is 2.083333333333, at position 4
The first harmonic number greater than 3 is 3.019877344877, at position 11
The first harmonic number greater than 4 is 4.027245195437, at position 31
The first harmonic number greater than 5 is 5.002068272680, at position 83
The first harmonic number greater than 6 is 6.004366708346, at position 227
The first harmonic number greater than 7 is 7.001274097134, at position 616
The first harmonic number greater than 8 is 8.000485571996, at position 1674
The first harmonic number greater than 9 is 9.000208062931, at position 4550
The first harmonic number greater than 10 is 10.000043008276, at position 12367
</pre>
 
2,468

edits