KEMBAR78
Examples of Pseudocode | PDF | Algorithms | Numbers
0% found this document useful (0 votes)
14 views3 pages

Examples of Pseudocode

This document contains three pseudocode programs to solve different mathematical problems. The first program calculates the area of a rectangle based on its base and height. The second program sums two grades entered by the user and calculates their product. The third program compares a number entered by the user and determines whether it is positive, negative, or zero.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Examples of Pseudocode

This document contains three pseudocode programs to solve different mathematical problems. The first program calculates the area of a rectangle based on its base and height. The second program sums two grades entered by the user and calculates their product. The third program compares a number entered by the user and determines whether it is positive, negative, or zero.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

Base, Height, Area are integer numbers.

Algorithm:

Enter the base and the height

read BASE, HEIGHT

calculate AREA = BASE * HEIGHT

The area of the rectangle is AREA

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

Environment: NOTE1, NOTE2, SUM, PRODUCT are integers

Algorithm:

Enter the notes

read NOTE1,NOTE2

calculate SUM = GRADE1 + GRADE2

calculate PRODUCT = GRADE1 * GRADE2

The sum of the two grades is: SUMA

The product of the two notes is: PRODUCT

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

Environment: NUMBER is an integer

Algorithm:

Enter a number

read NUMBER

IF NUMBER > 0 THEN

The entered number is positive

NO

IF NUMBER < 0 THEN

The entered number is negative

NO

The number is zero

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

The sum is, sum

end program

You might also like