Harmonic series: Difference between revisions

Content added Content deleted
m (Added language identifier and moved a comment.)
Line 233: Line 233:
250 next i
250 next i
260 end</syntaxhighlight>
260 end</syntaxhighlight>

==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">precision 5

print "the first twenty harmonic numbers are:"

for n = 1 to 20

let h = h + 1 / n
print n, tab, h

next n

print newline, "the nth index of the first harmonic number that exceeds the nth integer:"

let h = 1
let n = 2

for i = 2 to 10

do

if h < i then

let h = h + 1 / n
let n = n + 1

endif

wait

loop h < i

print tab, n - 1,

next i</syntaxhighlight>
{{out| Output}}<pre>
the first twenty harmonic numbers are:
1 1
2 1.50000
3 1.83333
4 2.08333
5 2.28333
6 2.45000
7 2.59286
8 2.71786
9 2.82897
10 2.92897
11 3.01988
12 3.10321
13 3.18013
14 3.25156
15 3.31823
16 3.38073
17 3.43955
18 3.49511
19 3.54774
20 3.59774

The nth index of the first harmonic number that exceeds the nth integer:
4 11 31 83 227 616 1674 4550 12375
</pre>


==={{header|Gambas}}===
==={{header|Gambas}}===