How to resolve the algorithm Square but not cube step by step in the CLU programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Square but not cube step by step in the CLU 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 CLU programming language
Source code in the clu programming language
square_not_cube = iter () yields (int)
cube_root: int := 1
square_root: int := 1
while true do
while cube_root ** 3 < square_root ** 2 do
cube_root := cube_root + 1
end
if square_root ** 2 ~= cube_root ** 3 then
yield(square_root ** 2)
end
square_root := square_root + 1
end
end square_not_cube
start_up = proc ()
amount = 30
po: stream := stream$primary_output()
n: int := 0
for i: int in square_not_cube() do
stream$putright(po, int$unparse(i), 5)
n := n + 1
if n // 10 = 0 then stream$putl(po, "") end
if n = amount then break end
end
end start_up
You may also check:How to resolve the algorithm Singly-linked list/Traversal step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the x86 Assembly programming language
You may also check:How to resolve the algorithm Empty directory step by step in the Wren programming language
You may also check:How to resolve the algorithm Reverse words in a string step by step in the Sparkling programming language
You may also check:How to resolve the algorithm Sorting algorithms/Shell sort step by step in the Pascal programming language