How to resolve the algorithm Harshad or Niven series step by step in the BASIC256 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Harshad or Niven series step by step in the BASIC256 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 BASIC256 programming language

Source code in the basic256 programming language

function sumDigitos(n)
	if n < 0 then return 0
	suma = 0
	while n > 0
		suma = suma + (n mod 10)
		n = n \ 10
	end while
	return suma
end function

function isHarshad(n)
	return n mod sumDigitos(n) = 0
end function

print "Los primeros 20 números de Harshad o Niven son:"
cuenta = 0
i = 1

do
	if isHarshad(i) then
		print i; " ";
		cuenta += 1
	end if
	i += 1
until cuenta = 20

print : print
print "El primero de esos números por encima de 1000 es:"
i = 1001

do
	if isHarshad(i) then
		print i; " "
		exit do
	end if
	i += 1
until false
end

  

You may also check:How to resolve the algorithm Golden ratio/Convergence step by step in the J programming language
You may also check:How to resolve the algorithm Pancake numbers step by step in the AWK programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the D programming language
You may also check:How to resolve the algorithm Set step by step in the Quackery programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the Delphi programming language