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

Published on 12 May 2024 09:40 PM

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

Source code in the pilot programming language

C :n=0
  :i=0
*first20
U :*harshad
C :i=i+1
T :#i: #n
J (i<20):*first20
C :n=1000
U :*harshad
T :First Harshad number greater than 1000: #n
E :
*harshad
C :n=n+1
  :r=n
  :s=0
*digit
C :a=r/10
  :s=s+(r-a*10)
  :r=a
J (r):*digit
J (n<>s*(n/s)):*harshad
E :

  

You may also check:How to resolve the algorithm Hello world/Text step by step in the sed programming language
You may also check:How to resolve the algorithm Totient function step by step in the C programming language
You may also check:How to resolve the algorithm Combinations step by step in the D programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the BASIC programming language
You may also check:How to resolve the algorithm Terminal control/Cursor movement step by step in the Axe programming language