You are on page 1of 7

SULIT

UNIVERSITI TEKNOLOGI MARA


FAKULTI KEJURUTERAAN ELEKTRIK

SKRIP JAWAPAN PEMERIKSA


PEPERIKSAAN: OKTOBER 2012

Kod Kursus : ECE246 (SET 1)


Nama Kursus : INTRODUCTION TO C PROGRAMMING

PART A

SOLUTION M

a) TRUE 1

b) FALSE 1

c) TRUE 1

d) TRUE 1

e) TRUE 1

f) FALSE 1

g) TRUE 1

h) FALSE 1

i) TRUE 1

j) TRUE 1

_______
TOTAL
10m
PART B

QUESTION : 1

SOLUTION M

a)
A: editing
1
B: pre-processing & compiling 1
C: execute 1

b) scanf:
input operation to get data from input peripherals
1
printf:
output operation to display data to output peripherals
1

c) Basic data types in C Language


• integer
• double, float 1
1
• character, string 1

d)
iteration i n m P
1 2 3 8 1
2 3 4 16 2 1
3 4 5 26 3 1
4 5 6 38 4 1
2
e) Flowchart

TOTAL
20m
QUESTION : 2

SOLUTION M

a)

Before : 5
7 5 4 2 1 8 3 9 2

After : 15
7 5 4 3 1 8 4 10 3

b)
The value of i is 4 2
The value of i is 2 2
The value of i is 2 1

_______
TOTAL
10m

QUESTION : 3

SOLUTION M
a)
int i, arrayOfInt[5]; 1
for(i=0 ; i<5 ; i++) { 2
arrayOfInt[i] = i + 4; 2
}

b)
void fcn(int *a) 1.5
{
*a=*a * 2; 1.5
}

main()
{
int a=8;
fcn(&a); 1
printf("After calling function, a=%d", a); 1
}
c)
int main()
{
float temperature;
int i;
2
for (i=1; i<=4; i++)
{
printf("Please enter the current temperature(0C): "); 1
scanf("%f",&temperature);

if((temperature>=0.00)&&(temperature<16.00)) 1
printf("The comfort level is cold!\n\n"); 1

else if((temperature>=16.00)&&(temperature<26.00)) 1.5


printf("The comfort level is mild!\n\n"); 1

else if((temperature>=26.00)&&(temperature<32.00)) 1.5


printf("The comfort level is warm!\n\n"); 1
else
printf("The comfort level is hot!\n\n");
}
return 0;
}

d)
i)
int array_number[2][3], i, j;
1
int k=3; 1
for(i=0; i<2; i++){ 2
for(j=0; j<3; j++){ 2
array_number[i][j]=k; 2
k=k+3; 2
}
}

ii) 2.5
for(i=0; i<3; i++){
2.5
array_number[0][i] += 1;
}

e)
iii) int *p_num; 2
int *p_arr;

iv) p_num = &num; 1


v) p_arr = arr_num; 1

vi) p_num = p_arr; 1

_______
TOTAL
40 m

PART C

QUESTION : 1

SOLUTION M

#include<stdio.h>
#include<math.h> 1

float my_hypotenuse(float s1, float s2); 2.5

main()
{
float s1, s2, h; 1
printf("Enter two sides value of a right angle 1
triangle:\n");
scanf("%f%f", &s1, &s2); 2
h = my_hypotenuse(s1, s2); 2
printf("The hypotenuse of this triangle is %.2f", h); 2
}
float my_hypotenuse(float a, float b) 2.5
{
float x, y; 1
x = (a*a) + (b*b); 3
y = sqrt(x); 1
return y; 1
}

_______
TOTAL
20m

You might also like