Lab Report 3
Lab Report 3
COMPUTER PROGRAMMING
(ECE411)
LABORATORY 3
FUNCTIONS
PREPARED BY:
NAME STUDENT NO. GROUP
ANISHA SHAHIRA BINTI SUBHI 2022868348 B2
RAJA NURUL ZAHRAA BINTI RAJA JAMAM 2022850856 B2
Program:
Output:
Discussion
In question 1, we need to write a function using C program that calculate the sum of two
integers. Firstly, we need to declare num1, num2, and sum. Then, we ask the user to
insert two integers. Then, the calculation will happen in the function and the sum of the
integers will be return to the main program. The output will show the sum of the integers.
2. Refer to the flowchart in Figure 2. Write a program based on the flowchart.\
Program:
Output i:
Output ii:
Discussion
This question require us to write a program based on the flowchart given. First, we need
to declare function compare (int x, int y) and main function variable (num1, num2). Then
we display the output “Input two integers” so the user can insert any integer. In the
function braces, we declare variables min and max. We use if-else selection to find both
max and min. After we display the output, we return the function into main program.
3. Write a program to include a function that calculates the count of odd integers
entered a user.
Program:
Output:
Discussion:
In this program, the question asked the user to counts the occurrence of odd integer.
The user need to write a function prototype and the main program contains for 5 integers
by using a looping. The user need to determine the function whether the integer is an
even or odd integer. Total of odd integers will be display in output.
4. Explain the operation of the code in Listing 1. Support the explanation with a sample
of output.
Program:
Output:
Discussion:
In this question, we need to write a program the calculate factorial number. First, we
must declare the variable ‘I’. Then, we use looping to count 4 factorial number. In
function, we wrote the formula to calculate the factorial number. Then, the answer will be
return into main program. The output will display the number that has been calculated.
Assignment
Program:
Output:
Discussion:
In this assignment, the question ask to write a programme about fees at UITM pre-school.
Create a main() function that asks the user how many children they want to enrol in the
school. Then, the calcFees function will be invoked by the main() function ().The main()
function will receive the total amount of school fees, including 6% GST, from the function
calcFees().