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

Published on 12 May 2024 09:40 PM

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

Source code in the action! programming language

INT FUNC SumOfDigits(INT a)
  INT sum

  sum=0
  WHILE a#0
  DO
    sum==+a MOD 10
    a==/10
  OD
RETURN (sum)

INT FUNC Next(INT a)
  INT sum

  DO
    a==+1
    sum=SumOfDigits(a)
  UNTIL a MOD sum=0
  OD
RETURN (a)

PROC Main()
  INT i,a

  a=0
  FOR i=1 TO 20
  DO
    a=Next(a)
    PrintI(a)
    Put(32)
  OD
  Print("... ")
  a=Next(1000)
  PrintIE(a)
RETURN

  

You may also check:How to resolve the algorithm Least common multiple step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Power set step by step in the Wren programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Semiprime step by step in the Objeck programming language
You may also check:How to resolve the algorithm MAC vendor lookup step by step in the Racket programming language