You are on page 1of 6

SULIT

UNIVERSITI TEKNOLOGI MARA


FAKULTI KEJURUTERAAN ELEKTRIK

SKRIP JAWAPAN PEMERIKSA


UJIAN 1: JULAI 2012

Kod Kursus : ECE246


Nama Kursus : INTRODUCTION TO C PROGRAMMING

QUESTION : 1

M
SOLUTION

a) FALSE 1

b) TRUE 1

c) FALSE 1

d) FALSE 1

e) TRUE 1

f) TRUE 1

g) TRUE 1

h) FALSE 1

i) FALSE 1

j) TRUE 1
______
TOTAL
10m
QUESTION : 2
SOLUTION M

a)

a b c d

int a = 0, b = 10, c = 5, d = 8; 0 10 5 8
b = ++a * b; 1 10 1

a *= c++; 5 5 1

c--; 6 0.5

d /= --c; 4 2 1

b = a % c++; 5 1 4 1.5

b)

______
TOTAL
10m
QUESTION : 3
SOLUTION M

a) Output:

Good afternoon 1
My favourite sport is tennis 1
I can speak Arabic 1
I have 1 brother and 2 sisters
2

b) Output:

This is a FOR loop 1


-3 -2 -1 1
This is a WHILE loop 1
-1 0 1
Count = 7 1

______
TOTAL
10m
QUESTION : 4

SOLUTION M

a)
i) printf(“Enter a mark in integer value: ”); 1

ii) scanf(“%d”, &mark); 1

iii) printf(“%d”, mark); 1

int i=10;
b)
int j=1;
while(i>=j){
if(i%4==0) 1
break; 1
i-=3; 1
} 1
printf("%d\t%d", i, j); 1
1
1

______
TOTAL
10m
QUESTION : 5

SOLUTION M

#include <stdio.h>
int main() 0.5
{
int year, month, date, state, id; 1

printf("Enter MyKad number (e.g: 831208-02-5618): "); 1


scanf ("%2d%2d%2d-%2d-%d", &year, &month, &date, &state, &id); 3

printf("\nDate of Birth is %d-%d-%d\n", date, month, year); 1.5

if(id%2 == 0) 1
printf("\nGender is female\n"); 0.5
else 1
printf("\nGender is male\n"); 0.5

return 0;
}

______
TOTAL
10m
QUESTION : 6

SOLUTION M
#include<stdio.h>
int main() 0.5
{
int n, sum=0;
int min,max; 1

printf("Enter the minimum range: ");


scanf("%d",&min); 1.5

if (min % 2 == 0) 1
{ min++; } 1

printf("\nEnter the maximum range: "); 1.5


scanf("%d",&max);

for(n=min;n<=max;n+=2) 1.5
{
sum += n; 1
}

printf("\nThe sum of odd numbers in given range is %d\n",sum); 1


return 0;
}
______
TOTAL
10m

You might also like