Harmonic series: Difference between revisions
Content added Content deleted
m (Now mentions which external crate the code needs) |
(Harmonic series in various BASIC dialents) |
||
Line 154: | Line 154: | ||
The first harmonic number > 10 is 10.00004301 at position 12367 |
The first harmonic number > 10 is 10.00004301 at position 12367 |
||
</pre> |
</pre> |
||
=={{header|BASIC}}== |
|||
==={{header|BASIC256}}=== |
|||
<lang freebasic>h = 0.0 |
|||
print "The first twenty harmonic numbers are:" |
|||
for n = 1 to 20 |
|||
h += 1.0 / n |
|||
print n, h |
|||
next n |
|||
print |
|||
h = 1 : n = 2 |
|||
for i = 2 to 10 |
|||
while h < i |
|||
h += 1.0 / n |
|||
n += 1 |
|||
end while |
|||
print "The first harmonic number greater than "; i; " is "; h; ", at position "; n-1 |
|||
next i |
|||
end</lang> |
|||
==={{header|QBasic}}=== |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<lang QBasic>h = 0! |
|||
PRINT "The first twenty harmonic numbers are:" |
|||
FOR n = 1 TO 20 |
|||
h = h + 1! / n |
|||
PRINT n, h |
|||
NEXT n |
|||
PRINT |
|||
h = 1: n = 2 |
|||
FOR i = 2 TO 10 |
|||
WHILE h < i |
|||
h = h + 1! / n |
|||
n = n + 1 |
|||
WEND |
|||
PRINT "The first harmonic number greater than "; i; " is "; h; ", at position "; n - 1 |
|||
NEXT i |
|||
END</lang> |
|||
==={{header|True BASIC}}=== |
|||
<lang qbasic>LET h = 0 |
|||
PRINT "The first twenty harmonic numbers are:" |
|||
FOR n = 1 TO 20 |
|||
LET h = h + 1 / n |
|||
PRINT n, h |
|||
NEXT n |
|||
PRINT |
|||
LET h = 1 |
|||
LET n = 2 |
|||
FOR i = 2 TO 10 |
|||
DO WHILE h < i |
|||
LET h = h + 1 / n |
|||
LET n = n + 1 |
|||
LOOP |
|||
PRINT "The first harmonic number greater than "; i; " is "; h; ", at position "; n - 1 |
|||
NEXT i |
|||
END</lang> |
|||
==={{header|Yabasic}}=== |
|||
<lang freebasic>h = 0.0 |
|||
print "The first twenty harmonic numbers are:" |
|||
for n = 1 to 20 |
|||
h = h + 1.0 / n |
|||
print n, chr$(9), h |
|||
next n |
|||
print |
|||
h = 1 : n = 2 |
|||
for i = 2 to 10 |
|||
while h < i |
|||
h = h + 1.0 / n |
|||
n = n + 1 |
|||
wend |
|||
print "The first harmonic number greater than ", i, " is ", h, ", at position ", n-1 |
|||
next i |
|||
end</lang> |
|||
=={{header|C++}}== |
=={{header|C++}}== |