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
a) Answers True or False for the following statements;
(6 marks)
b) Refer to the Listing Q1b, identify the missing statement or expression inside each of the
following programs. The corresponding output is given in the Figure Q1b.
(4 marks)
Source Code
void main()
{
int val;
printf(“ (i) ”);
scanf (“%d”,___(ii)___);
//Selective structure
if(___(iii)___)
printf(“\nYou have enter even number”);
else
printf(“\nYou have enter odd number”);
___(iv)___
;
}
Listing Q1b
Figure Q1b
QUESTION 2
a) Listing Q2a shows the program that is used to identify students’ intake year based on
matrix number. Illustrate the flowcharts that represent the selective statement only from
the source code given below.
(4 marks)
Source Code
#include <stdio.h>
#include <stdlib.h>
int main()
{
int matrixFirst;
int matrixLast;
return 0;
}
Listing Q2a
b) Modify program shown in Listing Q2b with the equivalent program by replacing switch
with if…else..if statement.
(6 marks)
int main()
{
char input;
printf( “Choose ‘r’ to turn right\n” );
printf( “Choose ‘l’ to turn left \n” );
printf( “Choose ‘s’ to stop \n” );
scanf( “%c”, &input );
switch ( input )
{
case ‘r’:
printf( “Go Right!\n” );
break;
case ‘l’:
printf( “Go Left!\n” );
break;
case ‘s’:
printf( “Stop Here!\n” );
break;
default:
printf( “Invalid!\n” );
break;
}
return 0;
}
Listing Q2b
QUESTION 3
#include <stdio.h>
int main()
{
char alpha='D';
int count=0;
char i;
for(i='A';i<=alpha;i++) {
printf("%c",i);
printf("%d\n",count);
count+=1;
}
printf("Number of alphabet is %d\n", count);
return 0;
}
Listing Q3a.
© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
CONFIDENTIAL 5 EE/JAN 2021/ECE128
b) Complete the programming code in Listing Q3b using a continue statement to produce
an output as shown in Figure Q3b.
(5 marks)
#include <stdio.h>
int main()
{ int count;
for(count=0;count<=10;count++) {
-------------------
-------------------
-------------------
}
return 0;
}
Listing Q3b
0 2 4 6 8 10
Figure Q3b