How to resolve the algorithm Square but not cube step by step in the Draco programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Square but not cube step by step in the Draco 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 Draco programming language

Source code in the draco programming language

proc main() void:
    word sqrt, cbrt, sq, cb, seen;
    sqrt := 1;
    cbrt := 1;
    seen := 0;
    while seen < 30 do
        sq := sqrt * sqrt;
        while
            cb := cbrt * cbrt * cbrt;
            sq > cb
        do
            cbrt := cbrt + 1
        od;
        if sq /= cb then
            seen := seen + 1;
            write(sq:5);
            if seen % 10 = 0 then writeln() fi
        fi;
        sqrt := sqrt + 1
    od
corp

  

You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Comments step by step in the Dragon programming language
You may also check:How to resolve the algorithm Xiaolin Wu's line algorithm step by step in the Ruby programming language
You may also check:How to resolve the algorithm JortSort step by step in the Python programming language
You may also check:How to resolve the algorithm Casting out nines step by step in the Common Lisp programming language