Universiti Tenaga Nasional: College of Computing and Informatics
Universiti Tenaga Nasional: College of Computing and Informatics
FINAL EXAMINATION
SEMESTER I 2019/2020
PROGRAMMING 1 WITH C
(CSNB144)
PROGRAMMING 1
(CSEB134)
September 2019
INSTRUCTIONS TO CANDIDATES
Page 1 of 10
SECTION A: MULTIPLE-CHOICE QUESTIONS
(10 QUESTIONS, 10 MARKS)
Instruction: Please choose the best answer. Each question worth 1 mark.
1. Select the task represented by the following flow chart symbol in Figure 1:
Figure 1
(A) Terminal
(B) Process
(C) Input/Output
(D) Printer output symbol
Page 2 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
4. Which of the following operators is NOT a relational operator in C?
(A) < >
(B) ==
(C) >=
(D) >
7. Based on the code below, how many times will the asterisk (*) be printed out.
for (point = 7; point > 0; point=-2)
printf("*");
(A) 8
(B) 7
(C) 5
(D) 4
Programming 1
9. Array declaration is made by specifying the ____________
(A) Data type, array name and array size.
(B) Data type and variable name.
(C) Data type and array size.
(D) Array name and array size.
Page 4 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
SECTION B: SHORT ANSWER QUESTIONS (6 QUESTIONS, 60 MARKS)
Instruction:Answer ALL questions.
Question 1
A snipped C program contains the following declaration and initial assignments
int a = 8, b = 5, x;
float x = 2.0, y= -1.0, z;
Determine the value of x in each of the following expressions. Use the values initially
assigned to the variables for each expression.
(c) c = (a += (b – 2))
[2 marks]
Question 2
Based on the C segment in code below
int x, y;
scanf("%d", &x);
if(x > 2)
if(x < 10)
if(x >= 5)
printf(“Welcome to UNITEN);
else
printf(“Today is final exam day”);
else
printf(“Good luck for your final exam”);
else
printf(“I like programming”);
Page 5 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
Trace the output of the above program if the input value for x is:
(a) 1
[1 mark]
(b) 5
[1 mark]
(c) 10
[1 mark]
Question 3
Change the while loop structure in code below using for loop without changing the
logic.
int ary[4] = { 1, 2, 3, 4 };
int p[4] = {};
int i = 0;
while (i<4) {
p[i] = ary[i] * i;
ary[i] = ary[i] + p[i];
i++;
}
printf("%d%d\n", p[2], ary[3]);
[6 marks]
Question 4
Given the main function below:
void main(){
int num1 = 10, num2 = 5, num3 = 6, minimum, total ;
char evenodd ;
minimum = min(num1, num2, num3);
evenodd = oddeven(num3);
add(&total,&num1, &num2);
}
(a) Write a function named min() that accept THREE (3) integers and returns the
smallest number of those three integers.
[6 marks]
Page 6 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
(b) Write a function name oddeven() that accept ONE (1) integer and return
character ‘O’ if the number is odd or character ‘E” is the number is even.
[5 marks]
(c) Write a function name add() that accept THREE (3) address (total, num1,
and num2) by using passing by reference. Add the variable of num1 and num2
and store the result at total.
[5 marks]
Question 5
Array1 and Array2 below are one dimensional integer arrays.
0 1 2 3 4
Array1 55 37 89 14 61
0 1 2 3 4
Array2 24 90 73 45 32
(a) Write C programming language statement(s) to declare and initialize the TWO
(2) arrays above.
[2 marks]
(b) Write loop statement(s) to display the content of Array1. (You are not
required to write a full program).
[4 marks]
(c) Write program statement(s) to sum up all the numbers in Array2. (You are
not required to write full program)
[5 marks]
Page 7 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
Question 6
Given the following C Program and answer the following questions
#include<stdio.h>
#include<string.h>
void main(void) {
char str1[15] = "I love";
char str2[100] = "Uniten";
int count;
strcat(str2, str1);
strncpy(str2, str1, 9);
count = strlen(str2);
printf("%s contains %d characters.\n", str2, count);
}
(b) Trace the output and explain what happens when each of the following
statements is executed.
i. strcat (str2, str1);
[4 marks]
Page 8 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
SECTION C: PROGRAMMING QUESTIONS (2 QUESTIONS, 30 MARKS)
Instruction:Answer ALL questions. Write a complete C program. Study the
problem carefully before you attempt to answer.
Question 1
You are required to write a program to perform the calculation of the amount of penalty
that need to pay by the book store customer. Your program is to accept the book price
from the user and the number of day (s) the book had overdue, the amount of penalty is
10% of the book price per day. If the amount of penalty is more than the book price,
then the system will advise the user to buy the book, otherwise the program will display
the amount of penalty. After display the answer, your program should ask the user
whether they wish to continue with the next book and your program should only stop,
if the user key in 0. Sample output as below:
Enter book price (press 0 to stop): RM 30.00
Enter day(s) book had overdue: 3
You need to pay RM9.00 for the penalty
[10 marks]
Question 2
You are required to write a complete C program that will read the exam marks and
names for 5 students. The range of the marks should be in between 0-100. The program
should consists THREE (3) functions:
Page 9 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1
A function name passfail( ). This function will accept the array of marks
then count and display the number of students passing and failing the exam.
(Tips: student needs to score at least 50 marks in order to pass an exam)
A function name below20(). This function will accept the array of marks and
the array of students. Next, it should find and print the names for those scoring
20 marks and below.
A function name max( ). This function will accept the array of marks and the
array of students. Next, find the top students whose get the highest marks and
display their name together with their marks.
You are required to declare your function prototypes, call the functions, and define the
functions precisely according to the problem given. Sample output as follow
Enter student 1: Ali
Enter marks: 60
Enter student 2: Siti
Enter marks: 300. Invalid marks.
Enter marks: 90
Enter student 3: Raju
Enter marks: 10
Enter student 4: Lim
Enter marks: 15
Enter student 30: Priya
Enter marks: 96
PASS : 3 students.
FAIL : 2 students.
[20 marks]
---End of Questions---
Page 10 of 10
Semester I 2019/2020 Programming 1 with C /
Programming 1