Lab2 Writing Simple Programs
Lab2 Writing Simple Programs
DEPARTMENT OF COMPUTER
ENGINEERING CEBU CITY, PHILIPPINES
LABORATORY ACTIVITY
2
WRITING SIMPLE
PROGRAMS
A. Objectives
a. To be able to write simple programs using the introduced programming language
and development tool
b. To be able to write program code solutions to simple mathematical problems
c. To be able to use program syntax on simple input/output of different data types
d. To be able to use constants and variables in the program
e. To be able to construct expressions and statements on the given problems
f. To be able to use and apply principles of arithmetic expressions and user-input
function.
B. Activity Instructions
Write your program on the code editor of the Integrated Development Environment
(IDE) software (DevC or other IDE or any code editor) you are using.
a. Run your Integrated Development Environment (IDE) offline or online.
Create new file under File Tab located at the left-most side of the IDE interface
Save your file and rename it LASTNAME_Problem#.c
b. Create a folder for all your laboratory activities in your computer. You should
separate program file for each activity problem under one folder. The folder name
should be your LASTNAME_ES9_LA2
c. Solve the programming problems found in Section D. There are sample input and
output for the problem (applicable) which you can reference.
d. Compile, run and debug your codes to check the correctness of the output of your
program.
e. If you are done writing your solution codes, submit LABORATORY REPORT in the
LMS on or before September 05, 2023 05:00PM.
C. Submission Instructions
Submit your work in the Adelante LMS – ES9 on the section Laboratory Activities
Submission for Laboratory Activity 2. Upload your laboratory report in pdf format with file
name LASTNAME_ES9_LA2.pdf. See the format for the laboratory report on the next
section E.
Problem No. 1 Write a program that asks for five integers and displays the mean.
Input/s n1, n2, n3, n4, and n5 are the five integers
Output/s mean is the mean of the five integers
Sample Test Data
Test No. INPUT OUTPUT
1 12345 3
2 6 7 8 9 10 8
3 11 12 13 14 15 15
4 10 20 30 40 50 30
5 22 45 67 88 90 62
Problem No. 2 Write a program that asks for two integers and performs addition,
subtraction, multiplication and division operations.
Input/s n1 and n2 are the two integers
Output/s sum, diff, prod, and quotient are the output of the operations
Sample Test Data
Test No. INPUT OUTPUT
1 55 3 58 52 165 18
2 -15 5 10 - 20 -75 -3
3 66 0 66 66 0 # (error)
4 0 -23 -23 23 0 0
5 100 1999 2099 -1899 199,900 0
Problem No. 3 Write a program to calculate the body mass index (BMI)
Input/s Using height and weight as inputs (assume the cm and kg SI unit)
Output/s bmi is the calculated BMI
Sample Test Data
Test No. INPUT OUTPUT
1 150 55 24.4
2 180 65 20.1
3 155 49 20.4
4 170 90 31.1
5 160 45 17.6
Problem No. 6 Write a program to solve for the distance formula given two points
Input/s PX1, PY1 are the coordinate of point 1, PX2, PY2 are the coordinate of
point 2
Output/s PD is the distance of two points
Sample Test Data
Test No. INPUT OUTPUT
1 (2,2) (3,-5) 7.07
2 (-3,0.2) (0,-3) 4.3863
3 (9,1) (2,10) 11.4017
4 (6,0) (10,-5) 6.4031
5 (1,6) (9,-5) 13.6014
Problem No. 7 Write the formula that solves the problem: A car takes 4 hours to
cover a certain distance when it travels at speed of 40 mph. What is
the speed of the car to cover the same distance in one hour and 30
minutes.
Input/s speed1 is the speed of the car, distance is the distance traveled by the
car, and traveltime is the time traveled by the car
Output/s speed2 is the speed of the car traveling in the same distance in one
hour and 30 minutes.
Expected formula written in C :
Problem No. 8 Write the formula to calculate the total resistance of a series
connected resistors.
Input/s R1, R2, R3 and R4 are the connected resistors
Output/s Total_R is the total resistance of the serially connected resistors
Expected formula written in C :
Problem No. 9 Write a program that solves the surface area of a rectangular prism by
asking the parameters by user-input.
Input/s PARAM1, PARAM2, PARAM3 are the known parameters to get the
surface area
Output/s AREA is the surface area of the rectangular prism
Expected formula written in C :
Problem No. Write a program that solves the monthly interest earned given the
10 principal amount and the annual interest.
Input/s P is the principal amount borrowed and Q is the annual interest rate
Output/s MON_INTEREST is the monthly interest
NAME
Laboratory Activity #
Title
A. PROGRAMMING SOLUTION/S
F. Grading
Each Problem is a total of 10 points. ( 3 points for correct input
implementation, 3 points for correct output implementation and 4 points
for correct arithmetic operation implementation). Total possible highest
score is 100 points.