How to resolve the algorithm Harshad or Niven series step by step in the Yabasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Harshad or Niven series step by step in the Yabasic programming language
Table of Contents
Problem Statement
The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits. For example, 42 is a Harshad number as 42 is divisible by (4 + 2) without remainder. Assume that the series is defined as the numbers in increasing order.
The task is to create a function/method/procedure to generate successive members of the Harshad sequence. Use it to:
Show your output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Harshad or Niven series step by step in the Yabasic programming language
Source code in the yabasic programming language
sub sumDigits(n)
if n < 0 then return 0 : endif
local sum
while n > 0
sum = sum + mod(n, 10)
n = int(n / 10)
wend
return sum
end sub
sub isHarshad(n)
return mod(n, sumDigits(n)) = 0
end sub
print "Los primeros 20 numeros de Harshad o Niven son:"
contar = 0
i = 1
repeat
if isHarshad(i) then
print i, " ",
contar = contar + 1
end if
i = i + 1
until contar = 20
print : print
print "El primero de esos numeros por encima de 1000 es:"
i = 1001
do
if isHarshad(i) then
print i, " "
break
end if
i = i + 1
loop
print
end
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Scala programming language
You may also check:How to resolve the algorithm Stack traces step by step in the Perl programming language
You may also check:How to resolve the algorithm Comments step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Percolation/Site percolation step by step in the Factor programming language