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

Published on 12 May 2024 09:40 PM

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

Source code in the nim programming language

var count = 0
var n, c, c3 = 1

while count < 30:
  var sq = n * n
  while c3 < sq:
    inc c
    c3 = c * c * c
  if c3 == sq:
    echo sq, " is square and cube"
  else:
    echo sq
    inc count
  inc n


  

You may also check:How to resolve the algorithm Range expansion step by step in the Jsish programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the APL programming language
You may also check:How to resolve the algorithm Simple turtle graphics step by step in the Wren programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the C++ programming language
You may also check:How to resolve the algorithm Pernicious numbers step by step in the Ring programming language