How to resolve the algorithm Count in factors step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in factors step by step in the PL/I programming language

Table of Contents

Problem Statement

Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself.

2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as

2 × 3

{\displaystyle 2\times 3}

. 2144   is not prime;   it would be shown as

2 × 2 × 2 × 2 × 2 × 67

{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}

.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count in factors step by step in the PL/I programming language

Source code in the pl/i programming language

cnt: procedure options (main);
	declare (i, k, n) fixed binary;
	declare first bit (1) aligned;

   do n = 1 to 40;
      put skip list (n || ' =');
      k = n; first = '1'b;
repeat:
      do i = 2 to k-1;
		if mod(k, i) = 0 then
			do;
				k = k/i;
                                if ^first then put edit (' x ')(A);
                                first = '0'b;
                                put edit (trim(i)) (A);
				go to repeat;
			end;

	end;
        if ^first then put edit (' x ')(A);
        if n = 1 then i = 1;
        put edit (trim(i)) (A);
   end;
end cnt;

  

You may also check:How to resolve the algorithm Repeat step by step in the Wren programming language
You may also check:How to resolve the algorithm Maximum triangle path sum step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Nial programming language
You may also check:How to resolve the algorithm Simple database step by step in the Python programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Bracmat programming language