How to resolve the algorithm Harmonic series step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Harmonic series step by step in the BASIC programming language
Table of Contents
Problem Statement
In mathematics, the n-th harmonic number is the sum of the reciprocals of the first n natural numbers: The series of harmonic numbers thus obtained is often loosely referred to as the harmonic series. Harmonic numbers are closely related to the Riemann zeta function, and roughly approximate the natural logarithm function; differing by γ (lowercase Gamma), the Euler–Mascheroni constant. The harmonic series is divergent, albeit quite slowly, and grows toward infinity.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Harmonic series step by step in the BASIC programming language
Source code in the basic programming language
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
100 cls
110 print "The first twenty harmonic numbers are:"
120 for n = 1 to 20
130 h = h+(1/n)
140 print n,h
150 next n
160 print
170 h = 1
180 n = 2
190 for i = 2 to 10
200 while h < i
210 h = h+(1/n)
220 n = n+1
230 wend
240 print "The first harmonic number greater than ";i;"is ";h;" at position ";n-1
250 next i
260 end
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
Public Sub Main()
Dim h As Float = 0
Dim n As Integer, i As Integer
Print "The first twenty harmonic numbers are:"
For n = 1 To 20
h += 1 / n
Print n, h
Next
Print
h = 1
n = 2
For i = 2 To 10
While h < i
h += 1 / n
n += 1
Wend
Print "The first harmonic number greater than "; i; " is "; h; ", at position "; n - 1
Next
End
100 CLS : REM HOME 100 HOME for Applesoft BASIC
110 PRINT "The first twenty harmonic numbers are:"
120 FOR n = 1 TO 20
130 h = h+(1/n)
140 PRINT n,h
150 NEXT n
160 PRINT
170 h = 1
180 n = 2
190 FOR i = 2 TO 10
200 IF NOT(h < i) THEN GOTO 240
210 h = h+(1/n)
220 n = n+1
230 GOTO 200
240 PRINT "The first harmonic number greater than " i "is " h "at position " n-1
250 NEXT i
260 END
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
print "The first twenty harmonic numbers are:"
for n = 1 to 20
h = h + 1 / n
print n; chr$(9);h ' print n,h for Just BASIC and Liberty BASIC
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
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
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
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Racket programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the Zig programming language
You may also check:How to resolve the algorithm Anti-primes step by step in the Forth programming language
You may also check:How to resolve the algorithm Narcissist step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Abbreviations, simple step by step in the Mathematica/Wolfram Language programming language