Lab 3 Programming
Lab 3 Programming
1
LAB 3: SELECTION STRUCTURES
Objective To write, compile and execute a program that uses floating point
numbers.
Questions
Enter number 1:
Enter number 2:
….
Enter Number 5:
2
y
Quadrant II Quadrant I
Fig. 3.1
2. Write a program that takes the x-y coordinates of a point in the
Cartesian coordinate system and displays the points entered while
informing the user in which quadrant (refer to Fig. 3.1) the point lies in.
3
Question 1
Pseudocode
START program
Declare variables: a, b, c, d, e (to store 5 numbers), sum, min, max, average
Prompt the user to enter 5 numbers
Calculate the sum of the numbers
sum = a + b + c + d + e
Calculate the average of the numbers
average = sum / 5
Display the sum and average
Use if statements to determine the maximum value among a, b, c, d, and e:
- Set max to a
- If b > max, set max to b
- If c > max, set max to c
- If d > max, set max to d
- If e > max, set max to e
Display the maximum value
Use if statements to determine the minimum value among a, b, c, d, and e:
- Set min to a
- If b < min, set min to b
- If c < min, set min to c
- If d < min, set min to d
- If e < min, set min to e
Display the minimum value
END the program
4
Flowchart
5
Programming Code
6
Question 2
Pseudocode
START
// Prompt the user to input the x and y coordinates of a point
PRINT "Enter the x-coordinate:"
READ x
PRINT "Enter the y-coordinate:"
READ y
PRINT “The point entered is x, y.”
// Determine and display the quadrant of the point
IF x > 0 AND y > 0 THEN
PRINT "The point lies in first quadrant."
ELSE IF x < 0 AND y > 0 THEN
PRINT "The point lies in second quadrant."
ELSE IF x < 0 AND y < 0 THEN
PRINT "The point lies in third quadrant."
ELSE IF x > 0 AND y < 0 THEN
PRINT "The point lies in fourth quadrant."
ELSE
PRINT "The point is at the origin or on the axis plane."
END
7
8
Programming Code