How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the MAD programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the MAD programming language

Table of Contents

Problem Statement

Note:   Niven   numbers are also called   Harshad   numbers.

Niven numbers are positive integers which are evenly divisible by the sum of its digits   (expressed in base ten). Evenly divisible   means   divisible with no remainder.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the MAD programming language

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            
            INTERNAL FUNCTION REM.(A,B) = A-A/B*B 
            
            PRINT COMMENT $ GAP NO  GAP  NIVEN INDEX  NIVEN NUMBER$
            PRINT COMMENT $ ******  ***  ***********  ************$
            VECTOR VALUES FMT = $I6,S2,I3,S2,I11,S2,I12*$

            PREV = 1
            GAP = 0
            SUM = 0
            NIVIX = 0
            GAPIX = 1
            
            THROUGH LOOP, FOR NIVEN=1, 1, GAPIX.G.22
            SUM = SUM + 1
            N = NIVEN
DSUM        WHENEVER N.G.0 .AND. REM.(N,10).E.0
                SUM = SUM - 9
                N = N / 10
                TRANSFER TO DSUM
            END OF CONDITIONAL
            WHENEVER REM.(NIVEN,SUM).E.0
                WHENEVER NIVEN.G.PREV+GAP
                    GAP = NIVEN-PREV
                    PRINT FORMAT FMT,GAPIX,GAP,NIVIX,PREV
                    GAPIX = GAPIX + 1
                END OF CONDITIONAL
                PREV = NIVEN
                NIVIX = NIVIX + 1
            END OF CONDITIONAL
LOOP        CONTINUE

            END OF PROGRAM

  

You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the RapidQ programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the RPL programming language
You may also check:How to resolve the algorithm Totient function step by step in the Java programming language