Professional Documents
Culture Documents
INSTRUCTIONS TO CANDIDATES
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
QUESTION 1
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
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
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)__);
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
Source Code
#include <stdio.h>
int main ( )
{
int weight;
printf ("Enter your weight: ");
scanf ("%d", &weight);
return 0;
Listing Q2b
QUESTION 3
Source Code
#include <stdio.h>
int main ( )
{
char *ABC;
int num;
return 0;
}
Listing Q3a.
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