Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Computer Mathematics February 2,2023

Duration 1 hour (10:00 AM to 11:00 AM)

In Class Work Sheet

Logic Gates and algorithms

Question 1.

Write the algorithm based on the scenario below and construct a flow chart using the same
scenario.

Write and algorithm that add two numbers 40 and 50.Ensure that you take the variable sum and
initialize it to zero. Input the two numbers. Add the numbers and print the sum.

PSUDOCODE-

START

Declare

variables

Constant

Num1 = 40

Num2 = 50

Writeln (“Please enter the first number”)

Readln (num1)

Writeln (“please enter the second number”)

Readln (num2)

Sum = 0

Sum = num1 + num2

Writeln (“the sum is”, sum)

STOP
Question 2

Given the pseudocode for a loop draw a flow chart to find the sum of 6 numbers.

Algorithm (in simple English)

1. Initialize sum = 0 and count = 0    (PROCESS)


2. Enter n    
3. Find sum + n and assign it to sum and then increment count by 1 (PROCESS)
4. Is count < 6 (DECISION)
5. if YES go to step 2
else
Print sum

START

Sum = 0

Count = 0

Enter value
for n

Sum + n

IF NO
Count = count+1 coun Print Sum
t <6
YES

STOP
Question 3
Write pseudo code that will

a) Read in 5 individual numbers.

b) Calculate the average of the five numbers.

c) Find the smallest (minimum) and largest (maximum) of the five entered numbers.

PSUEDOCODE

START

Variables

Num :array[1..5] of real

avg, maximum, minimum, y, sum :real

sum := 0

y :=0

Writeln (“please enter a number”)

Readln (num[y])

sum= (sum+ num[y])

avg = sum/5

Writeln (“the average of all five numbers are”, avg)

Maximum = max\ num[y]

Writeln (“the largest number is”, maximum)

Minimum = min\ num[y]

Writeln (“the smallest number is”, minimum)

STOP

You might also like