How to resolve the algorithm Square but not cube step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Square but not cube step by step in the ALGOL 68 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 ALGOL 68 programming language
Source code in the algol programming language
BEGIN
# list the first 30 numbers that are squares but not cubes and also #
# show the numbers that are both squares and cubes #
INT count := 0;
INT c := 1;
INT c3 := 1;
FOR s WHILE count < 30 DO
INT sq = s * s;
WHILE c3 < sq DO
c +:= 1;
c3 := c * c * c
OD;
print( ( whole( sq, -5 ) ) );
IF c3 = sq THEN
# the square is also a cube #
print( ( " is also the cube of ", whole( c, -5 ) ) )
ELSE
# square only #
count +:= 1
FI;
print( ( newline ) )
OD
END
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the Java programming language
You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the Tcl programming language
You may also check:How to resolve the algorithm Extend your language step by step in the Delphi programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the REBOL programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the Arturo programming language