Rayad S.
Ali
4.2 IT
Problem #7
Write a program that accepts two whole numbers. It then determines
which number is larger and prints the larger number of the two
numbers.
I.P.O Chart.
Input Processing Output
Number 1 (1). Read Number 1 Prints
the larger of two
Number 2 (2).Read Number 2 numbers
(3).Determine if Number
1 is larger than Number 2
(4).Prints the larger of
the two numbers
Pseudocode Algorithm
Algorithm Larger of two numbers
This algorithm reads two whole numbers. It then determine which is
the larger number of the two. It will then print the larger of the two
numbers.
Variable Name Variable Data Type Variable Description
Num1 Integer Stores the value of
Number 1
Num2 Integer Stores the value
Number 2
LargeNum Integer Stores the larger
number of the two
numbers
Rayad S. Ali
4.2 IT
START
Read Num1
Read Num2
If Num 1 > Num2 then
LargeNum=Num1
Print LargeNum
Else
LargeNum=Num2
Print LargeNum
End if
STOP
Rayad S. Ali
4.2 IT
Flowchart
START
Read Num1
Read Num2
Yes No
Num1>Num2
LargeNum=Num1 LargeNum=Num2
Print LargeNum Print LargeNum
STOP
Rayad S. Ali
4.2 IT
Trace Table
Test Data Set #1
Num1=16
Num2=25
Instructions in execution Num1 Num2 Output
START
Read Num1 16
Read Num2 25
If Num1 > Num2 then
Else
LargeNum=Num2
Print LargeNum 25* LargeNum=25
End if
STOP
Rayad S. Ali
4.2 IT
Trace Table
Test Data Set #2
Num1=73
Num2=46
Instructions in execution Num1 Num2 Output
START
Read Num1 73
Read Num2 46
If Num1 > Num2 then
LargeNum=Num1
Print LargeNum 73* LargeNum=73
End if
STOP
Pascal Program
Rayad S. Ali
4.2 IT
Program Larger_of_two_numbers; // This is the Program Header //
//This program reads two whole numbers. It then determine which is
the larger number of the two. It will then print the larger of the two
numbers.//
Var // This is the Variable Declaration //
Num1:Integer;
Num2:Integer;
LargeNum:Integer;
BEGIN // The body of the program starts here //
st
Writeln ('Please enter the 1 whole number');
Readln (Num1);
Writeln ('Please enter the 2nd whole number');
Readln (Num2);
IF Num1 > Num2 THEN
BEGIN
LargeNum:=Num1;
Writeln ('The larger number is ’, Num1);
END
ELSE
BEGIN
LargeNum:=Num2;
Writeln ('The larger number is ’, Num2);
END;
Readln;
END. // The body of the program ends here //