How to resolve the algorithm Square but not cube step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Square but not cube step by step in the PL/I programming language
Table of Contents
Problem Statement
Show the first 30 positive integers which are squares but not cubes of such integers. Optionally, show also the first 3 positive integers which are both squares and cubes, and mark them as such.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Square but not cube step by step in the PL/I programming language
Source code in the pl/i programming language
squareNotCube: procedure options(main);
square: procedure(n) returns(fixed);
declare n fixed;
return(n * n);
end square;
cube: procedure(n) returns(fixed);
declare n fixed;
return(n * n * n);
end cube;
declare (ci, si, seen) fixed;
ci = 1;
do si = 1 repeat(si + 1) while(seen < 30);
do while(cube(ci) < square(si));
ci = ci + 1;
end;
if square(si) ^= cube(ci) then do;
put edit(square(si)) (F(5));
seen = seen + 1;
if mod(seen,10) = 0 then put skip;
end;
end;
end squareNotCube;
You may also check:How to resolve the algorithm Chinese zodiac step by step in the Scala programming language
You may also check:How to resolve the algorithm Scope modifiers step by step in the TI-89 BASIC programming language
You may also check:How to resolve the algorithm Guess the number step by step in the Ursa programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the Groovy programming language
You may also check:How to resolve the algorithm Literals/Floating point step by step in the Quackery programming language