How to resolve the algorithm Harshad or Niven series step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Harshad or Niven series step by step in the Ada 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 Ada programming language
Source code in the ada programming language
with Ada.Text_IO;
procedure Harshad is
function Next(N: in out Positive) return Positive is
function Sum_Of_Digits(N: Natural) return Natural is
( if N = 0 then 0 else ((N mod 10) + Sum_Of_Digits(N / 10)) );
begin
while not (N mod Sum_Of_Digits(N) = 0) loop
N := N + 1;
end loop;
return N;
end Next;
Current: Positive := 1;
begin
for I in 1 .. 20 loop
Ada.Text_IO.Put(Integer'Image(Next(Current)));
Current := Current + 1;
end loop;
Current := 1000 + 1;
Ada.Text_IO.Put_Line(" ..." & Integer'Image(Next(Current)));
end Harshad;
You may also check:How to resolve the algorithm Conditional structures step by step in the i programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Image noise step by step in the PL/I programming language
You may also check:How to resolve the algorithm Strong and weak primes step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Continued fraction/Arithmetic/G(matrix ng, continued fraction n) step by step in the Ruby programming language