Examples of Pseudocode
Examples of Pseudocode
Example: Create the pseudocode for a program that allows calculating the area of a
rectangle. The base and height must be entered to perform the calculation.
Program
Algorithm:
Finprogram
Example: Write the pseudocode that allows the user to input two grades from the keyboard,
calculating the sum and the product of the grades.
Program: SumProduct
Algorithm:
read NOTE1,NOTE2
Finprogram
Example: Create the pseudocode for a program that allows you to determine if a number is
greater than, less than or equal to zero.
Program: CompareNumbers
Algorithm:
Enter a number
read NUMBER
NO
NO
FINISH
FINISH
Financial program
Let's suppose an algorithm that reads the coordinates of three points and moves them three points in the
coordinatexy write the result on some output device:
ALGORITHM read_three_vertices
ENTRY: the coordinates (x,y) of three points
OUTPUT: the coordinates (x,y) of the three points moved 3 points to the right.
VARIABLES: i:integer
x,y: real
START
FOR i=1 TO 3 WITH INCREMENT +1
Abscissa of point number
READ x
Write 'Ordinate of point number ', i
READ AND
The point is ("x+3", "y")
FIN_PARA
END
The equivalent program to this algorithm is shown below. As we can see in a
In Pascal programming, it is extremely important not to forget syntax details. For example, each statement
it ends with a semicolon. In any case, it is immediately noticeable the simple changes that exist.
program read_three_vertices;
var x, y: real;
i:integer;
begin
for i:=1 to 3 do
begin
write ('Abscissa of point number ',i); readln(x);
write ('Ordered from point number ',i); readln(y);
Write line (' The point is (', x+3, ',', y, ')');
end;
end;
Problem: calculate and display the sum of the first ten numbers
between 1 and 1000 that are divisible by a given one.
divisible_sum program
variables natural : divisor, suma, contador, número
start program
Enter the divisor:
sum 0
counter 0
for number from 1 to 1000 do
if divisor divides a number then
sum sum + number
counter counter + 1
finally if
if counter = 10 then
interrupt
finish if
end for
end program