Final Question + Answer FSK1015 3202223
Final Question + Answer FSK1015 3202223
DURATION : 3 HOURS
INSTRUCTIONS TO CANDIDATES:
1. This examination paper consists of ELEVEN (11) questions. Answer ALL questions.
SESSION/SEMESTER : SESSION 2020/2021 SEMESTER II
2. All answers to a new question should start on a new page.
3. All calculations and assumptions must be clearly stated.
4. Candidates are not allowed to bring any materials other than those allowed by the
invigilator into the examination room.
EXAMINATION REQUIREMENTS:
1. Answer booklet
This examination paper consists of NINE (9) printed pages including the front page.
CONFIDENTIAL 2223III/FSK1015
(a)
#include <stdio.h>
int main(void) {
int i = 2;
do
{
if(i++ == 4)
continue;
printf("%d\n", i);
i += 1;
} while(i < 10);
return 0;
}
Answer
3
6
8
10
[2 Marks]
(b)
#include <stdio.h>
int main(void) {
int x = 4, y = 8;
switch(y > x || x – y > 0)
{
case 1:
x *= x + 3;
printf("x is %d", x);
break;
case 0:
y –= 3;
printf("y is %d", y);
break;
default:
printf(" Hello bye ");
2
CONFIDENTIAL 2223III/FSK1015
return 0;
}
Answer
x = 4*7 = 28
x is 28
[2 Marks]
(c)
#include <stdio.h>
int main(void) {
int x = 10;
if(x! = 10)
x++;
else
x– –;
return 0;
}
Answer
The value of x is 9
[2 Marks]
(d)
#include <stdio.h>
int main(void) {
int i = 0;
while (++i) {
printf(“H”);
}
return 0;
}
Answer
Unlimited H will be printed/infinite loop of H
[2 Marks]
3
CONFIDENTIAL 2223III/FSK1015
(e)
#include <stdio.h>
int main(void) {
int x, count=0;
Answer
x is 2
x is 3
x is 5
x is 6
x is 7
x is 8
x is 9
x is 10
[4 Marks]
QUESTION 2 [6 MARKS]
#include <stdio.h>
int main(void) {
int x, y;
if (y == 8)
if (x == 5)
printf("@@@@@\n");
else
printf("#####\n");
printf("$$$$$\n");
printf("&&&&&");
return 0;
}
4
CONFIDENTIAL 2223III/FSK1015
(a) x = 5, y =8
Answer
@@@@@
$$$$$
&&&&&
[2 Marks]
(b) x = 6, y =8
Answer
#####
$$$$$
&&&&&
[2 Marks]
(c) x = 5, y =9
Answer
$$$$$
&&&&&
[2 Marks]
QUESTION 3 [6 MARKS]
Identify whether the following declarations and initializations of arrays in C are valid or
invalid:
(a) int size;
int marks[size];
Invalid
(b) int marks[105];
Valid
(c) #define size 105
:
int marks[size];
Valid
(d) int result[5] = {34, 48, 78};
Valid
5
CONFIDENTIAL 2223III/FSK1015
QUESTION 4 [6 MARKS]
6
CONFIDENTIAL 2223III/FSK1015
Design a flowchart for the steps in baking cookies below. (Hint: the underline word is the
keyword for the flowchart)
(1) Prepare ingredients such as flour, sugar, butter, cream, salt and baking soda for baking
cookies.
(2) Check the temperature of the oven. If the temperature of the oven is 180°C, proceed to
the next step. If not, preheat the oven to 180°C.
(3) Mix the sugar, butter, cream in a mixer.
(4) Beat the mixture.
(5) Check if the mixture is creamy. If the mixture is creamy, proceed to the next step. If
not, continue to beat the mixture.
(6) Sift the flour, salt and baking soda into the mixture.
(7) Stir the mixture.
(8) Shape the mixture by using a tablespoon or an ice cream scooper, depending on your
desired cookie size.
(9) Place the mixture on a greased cookie sheet.
(10) Bake the mixture for 15 minutes.
(11) Cookies are ready to eat.
7
CONFIDENTIAL 2223III/FSK1015
Answer
[15 Marks]
8
CONFIDENTIAL 2223III/FSK1015
Write the output of the following program. Show all your steps before arriving to final answer.
#include <stdio.h>
int main(void) {
int i;
double x[5], z[5];
double y[5] = {1, 3, –1, 1, –1};
x[0] = 2.35; x[1] = –1; x[2] = 0.8; x[3] = 0.95; x[4] = –5.5;
return 0;
}
Answer
[10 Marks]
9
CONFIDENTIAL 2223III/FSK1015
QUESTION 7 [5 MARKS]
#include <stdio.h>
int main(void) {
int i, z, p;
int x = 2, y = 3;
int m = 5, n = 6;
return 0;
}
Table 1
i x y z
1 2 4 5
2 1 5 5
[2 Marks]
Table 2
i m n p
1 6 4 7
2 7 2 8
3 8 0 9
[3 Marks]
10
CONFIDENTIAL 2223III/FSK1015
Write a program to ask user to enter two numbers, which are denoted by x and y, then
Answer
#include <stdio.h>
int main(void) {
return 0;
}
[10 Marks]
11
CONFIDENTIAL 2223III/FSK1015
Write a program to calculate the water bill for customers. The bill comprises of RM 3 basic
charge and the charge for total water used. The rate of the water cost is RM 0.80 for each
thousand gallon used. Amount of water used is calculated by subtracting the meter reading (in
gallon thousand unit) for the previous month from the current month. The meter readings for
previous and current months should be input by users. Your program should display the final
amount to be paid by the customer.
Answer
#include <stdio.h>
int main(void) {
return 0;
}
[10 Marks]
12
CONFIDENTIAL 2223III/FSK1015
QUESTION 10 [8 MARKS]
Write a program to produce the output in Figure 1 below. (Hint: use nested for loops)
Figure 1
Answer
#include <stdio.h>
int main(void) {
int i, j, k;
return 0;
}
[8 Marks]
13
CONFIDENTIAL 2223III/FSK1015
Write a program to ask user to enter the values of radius and height of an object, then calculate
the volumes of a cylinder and a sphere, respectively. The calculation of volumes should be
performed in two separate functions as below:
Figure 2
4 3
The volume of a cylinder is given by r 2 h while the volume of a sphere is r . Display the
3
volumes in 2 decimal places.
(Note: π = 3.142)
14
CONFIDENTIAL 2223III/FSK1015
Answer
#include <stdio.h>
#define pi 3.142
int main(void) {
return 0;
}
float sphere(float r)
{
float Volume;
Volume = (4.0/3)*pi*r*r*r;
return Volume;
[12 Marks]
15