How to resolve the algorithm Square but not cube step by step in the Pascal programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Square but not cube step by step in the Pascal 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 Pascal programming language
Source code in the pascal programming language
program SquareButNotCube;
var
sqN,
sqDelta,
SqNum,
cbN,
cbDelta1,
cbDelta2,
CbNum,
CountSqNotCb,
CountSqAndCb : NativeUint;
begin
CountSqNotCb := 0;
CountSqAndCb := 0;
SqNum := 0;
CbNum := 0;
cbN := 0;
sqN := 0;
sqDelta := 1;
cbDelta1 := 0;
cbDelta2 := 1;
repeat
inc(sqN);
inc(sqNum,sqDelta);
inc(sqDelta,2);
IF sqNum>cbNum then
Begin
inc(cbN);
cbNum := cbNum+cbDelta2;
inc(cbDelta1,6);// 0,6,12,18...
inc(cbDelta2,cbDelta1);//1,7,19,35...
end;
IF sqNum <> cbNUm then
Begin
writeln(sqNum :25);
inc(CountSqNotCb);
end
else
Begin
writeln(sqNum:25,sqN:10,'*',sqN,' = ',cbN,'*',cbN,'*',cbN);
inc(CountSqANDCb);
end;
until CountSqNotCb >= 30;//sqrt(High(NativeUint));
writeln(CountSqANDCb,' where numbers are square and cube ');
end.
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Octave programming language
You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Cantor set step by step in the BASIC programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Objective-C programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element insertion step by step in the Visual Basic .NET programming language