Bounded Iteration Example

Task

Create an algorithm in flowchart AND pseudocode to accomplish the following task:

“output the squares of all numbers from 2 to 75 inclusive”.

Flowchart Solution

Flowchart
Solution as expected by CXC CSEC and NEC

The solution was also generated in Flowgorithm and is shown below:

Flowchart - 2

Similar solution generated in Flowgorithm

Pseudocode

The solution in PSEUDOCODE is shown below:

Start
For i = 2 to 75
Output i , ” Squared is ” , i * i
EndFor
End

BONUS: Coded solutions!

Pascal

The pascal code for the above algorithm is shown below:

Pascal Code

Solution in bloodshed Dev Pascal

Copy-able code:
program Squares;
uses
crt;
var
i:integer;
begin
for i:=2 to 75 do
writeln (i, ‘ squared is ‘ , i*i);
writeln();
writeln(‘Press any key to continue…’);
readkey();
end.

C# Solution

The following is a solution in C#:

C# Code

Solution created using Visual Studio Community Edition

See here for instructions on setting up Visual Studio to start using C#

Copy-able code:
using System;
namespace Squares
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 75; i++)
Console.WriteLine(i + ” squared is ” + (i * i));
//pause execution here
Console.WriteLine(“press any key to continue….”);
Console.ReadKey();
}
}
}
© 2018 Vedesh Kungebeharry. All rights reserved

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s