0% found this document useful (0 votes)
3 views

Lab 3 Programming

Uploaded by

227604
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab 3 Programming

Uploaded by

227604
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

K5

ENG3202 Computer Programming 2024-2025


LAB 3 : SELECTION STRUCTURES

NAME : AMIRRUL HEBAT BIN AZRI


MATRIC NO. : 228081
GROUP : K5

1
LAB 3: SELECTION STRUCTURES

Objective To write, compile and execute a program that uses floating point
numbers.

Equipment Personal Computer with C Program Pre-Installed

General guideline for all lab exercises and reports:


a. Generate a pseudocode for the program.
b. Generate a flow chart for the program
c. Provide relevant comments on the codes
d. In the case of compiling given program, run the program and record
any errors encountered.
e. Debug the error, compile and run the program. Record the program
output.
f. If you are required to design a program, design working codes,
debug and run as well as show the output.
g. Provide discussion and analysis of your results.
h. You may copy the program and results images or screenshot from
the IDE and paste it into your report

Questions

1. Write, compile and execute a C program that will

a. Prompt the user for 5 floating numbers as shown below.

Enter number 1:
Enter number 2:
….
Enter Number 5:

b. Find the minimum and maximum values among these 5 numbers


using if
statements

c. Compute the average from these numbers

d. Output a suitable printout e.g. Prints “You entered 5


numbers. The minimum is xx, the maximum is yy and the average
is zz”

2
y

Quadrant II Quadrant I

Quadrant III Quadrant IV

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

Discussion and Analysis


The C++ program prompts the user to input five numbers, stores them in variables
a, b, c, d, and e, and calculates their sum and average. It then uses if statements
to determine the maximum and minimum values among the inputs, updating the
max and min variables as needed. Finally, it displays the calculated sum, average,
maximum, and minimum values.

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

Discussion and Analysis


After receiving the user's x and y coordinates, this program calculates the point's
quadrant or axis location in the Cartesian coordinate system and outputs the
outcome. If the point is not on an axis, the program uses conditional logic to
determine which quadrant (I, II, III, or IV) it is in. Additionally, it manages unique
situations in which the point is at the origin, on the X-axis, or on the Y-axis. The
program works well for comprehending Cartesian coordinates and point locations
because it produces output that is easy to understand.

You might also like