How to resolve the algorithm Proper divisors step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Proper divisors step by step in the XPL0 programming language

Table of Contents

Problem Statement

The   proper divisors   of a positive integer N are those numbers, other than N itself, that divide N without remainder. For N > 1 they will always include 1,   but for N == 1 there are no proper divisors.

The proper divisors of     6     are   1, 2, and 3. The proper divisors of   100   are   1, 2, 4, 5, 10, 20, 25, and 50.

Show all output here.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Proper divisors step by step in the XPL0 programming language

Source code in the xpl0 programming language

func PropDiv(N, Show);  \Count and optionally show proper divisors of N
int  N, Show, D, C;
[C:= 0;
if N > 1 then
    [D:= 1;
    repeat  if rem(N/D) = 0 then
                [C:= C+1;
                if Show then
                    [if D > 1 then ChOut(0, ^ );
                    IntOut(0, D);
                    ];
                ];
            D:= D+1;
    until   D >= N;
    ];
return C;
];

int N, SN, Cnt, Max;
[for N:= 1 to 10 do
    [ChOut(0, ^[);  PropDiv(N, true);  ChOut(0, ^]);
    ChOut(0, ^ );
    ];
CrLf(0);

Max:= 0;
for N:= 1 to 20000 do
    [Cnt:= PropDiv(N, false);
    if Cnt > Max then
        [Max:= Cnt;  SN:= N];
    ];
IntOut(0, SN);  ChOut(0, ^ ); IntOut(0, Max);  CrLf(0);
]

  

You may also check:How to resolve the algorithm Create a file step by step in the 11l programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the Perl programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the X86 Assembly programming language
You may also check:How to resolve the algorithm Generator/Exponential step by step in the REXX programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the PowerShell programming language