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

Lab Report 3

This document discusses a computer programming laboratory assignment on functions at Universiti Teknologi MARA. It includes 4 questions that require students to write C programs involving functions to calculate the sum of integers, compare integers, count odd integers, and calculate factorials. The assignment asks students to write a program about calculating school fees for enrolling children in UITM's pre-school using functions.

Uploaded by

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

Lab Report 3

This document discusses a computer programming laboratory assignment on functions at Universiti Teknologi MARA. It includes 4 questions that require students to write C programs involving functions to calculate the sum of integers, compare integers, count odd integers, and calculate factorials. The assignment asks students to write a program about calculating school fees for enrolling children in UITM's pre-school using functions.

Uploaded by

anisha shahira
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

FACULTY OF ELECTRICAL ENGINEERING

UNIVERSITI TEKNOLOGI MARA

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

Date of submission: 5/1/2023

LECTURER DR SAIFUL ZAIMY BIN YAHYA


1. Write a function using C to calculate the sum of two integers. The function is being
called from the main program and it returns the result to the main program. The
function has the following characteristics.

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().

You might also like