You are on page 1of 5

CONFIDENTIAL CE/JUN 2023/ECE128

UNIVERSITI TEKNOLOGI MARA


WRITTEN TEST

COURSE : COMPUTER PROGRAMMING


COURSE CODE : ECE128
EXAMINATION : 22 JUNE 2023
TIME : 1.5 HOURS

INSTRUCTIONS TO CANDIDATES

1. This question paper consists of three (3) Questions

2. Answer ALL questions in the Answer Sheet.

NAME
STUDENT ID GROUP
LECTURER
QUESTION CLO-PLO MARKS
1a CLO1-PLO1
1b CLO1-PLO1
2a CLO1-PLO1
2b CLO1-PLO1
3a CLO1-PLO1
3b CLO1-PLO1

TOTAL MARKS

DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO


This examination paper consists of 5 printed pages
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 2 CE/JUN 2023/ECE128

QUESTION 1

a) Identify the following statements with True or False.


i. C programs are converted into machine language with the help of a program called
Editor.
ii. Spaces and commas are allowed in a variable name.
iii. The maximum value that an integer constant can have varies from one compiler to
another.
iv. A real constant in C can be expressed in both Fractional and Exponential forms.
v. #define is known as preprocessor compiler directive.
vi. Algorithm is the graphical representation of logic.
(6 marks)
b) Find the best answer following questions.
i. Which of the following do not describe the term ‘machine language’?
A. The natural language of a computer
B. Easy to understand by programmers
C. Contains binary numbers
D. All of the above

ii. A program was able to run successfully. However, the result is not as expected. This
is due to:
A. Systematic error
B. Semantic error
C. Random error
D. Syntax error

iii. Which of the following is an incorrect variable declaration?


A. _123Num
B. Num_123
C. Num 123
D. All of the above

iv. A variable of type float is declared as ROX and contains a value of 45.678. What will
the statement printf(“%8.3f”, ROX) produce?
A. 45.678_ _
B. _ _45.678
C. 0045.678
D. 45.67800

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 3 CE/JUN 2023/ECE128

QUESTION 2

a) Identify the missing command in the Listing Q2a to produce an output as shown in Figure
Q2a.

(4 marks)
Source Code
#include <stdio.h>

int main ( )
{
___(i)___ num1, num2, sum;
printf(“______(ii)______\n”);
__(iii)___(“%__(iv)__”, &num1);
printf(“______(v)_______\n”);
scanf(“%__(vi)__”, __(vii)__);

__(viii)__ = num1 + num2;


printf(“The sum of both integers is: %d ”, sum);
}
Listing Q2a

SAMPLE OUTPUT
Enter a first integer: 1
Enter a second integer: 2
The sum of both integers is: 3

Figure Q2a

b) Table Q2b shows a weight range and a message for the user on the LCD screen. The
program displays “Invalid value” if the weight is not in the list. Solve the incomplete code
program in Listing Q2b to display all the messages based on Table Q2b.

(6 marks)
Table Q2b
Weight LCD Display
60 kg above Run! You are overweight!
45 kg – 59 kg Simply lovely. Go shopping.
Below 44 kg What are you? A stick?
weight not on the list Invalid values

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 4 CE/JUN 2023/ECE128

Source Code
#include <stdio.h>

int main ( )
{
int weight;
printf ("Enter your weight: ");
scanf ("%d", &weight);

if (weight >= 60)


printf ("Run! You are overweight!");
……………….
……………….
……………….

return 0;

Listing Q2b

QUESTION 3

a) Write the output for the code shown in Listing Q3a.


(5 marks)

Source Code

#include <stdio.h>

int main ( )
{
char *ABC;
int num;

for (ABC= 'A'; ABC < 'J'; ABC+=2)


{
for (num=1; num<3; num++)
printf ("%c %d \n", ABC, num);
}

return 0;
}

Listing Q3a.

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL


CONFIDENTIAL 5 CE/JUN 2023/ECE128

b) Based on the sample result displayed in Figure Q3b, choose the appropriate statement
labelled as (i) through (iv) in Listing Q3b. Ten (10) integer numbers from the user should
be read by the program. The program will locate the highest and lowest input values and
show them on the screen.
(5 marks)

Source Code
#include <stdio.h>
#include <stdlib.h>

int main()
{
int highest = 0;
int lowest = 100000;
int i,num;

for ( __________(i)___________ )
{
printf("Please Enter a number : ");
scanf ( ______(ii)_______ );
if(num>highest)
{ highest=num; }

if(num<lowest)
____________(iii)____________
}
printf("\n\nHighest value = %d\n", _____(iv)______);
printf("lowest value = %d\n", ____(v)_____);

return 0;
}

Listing Q3b

SAMPLE OUTPUT:
Please Enter a number : 50
Please Enter a number : 55
Please Enter a number : 68
Please Enter a number : 99
Please Enter a number : 82
Please Enter a number : 46
Please Enter a number : 34
Please Enter a number : 45
Please Enter a number : 12

Highest value = 99
lowest value = 12

Figure Q3b

END OF QUESTION PAPER

© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like