You are on page 1of 8

HCMC UNIVERSITY OF FINAL EXAMINATION

TECHNOLOGY AND EDUCATION


SEMESTER 1 – ACADEMIC YEAR 2019-2020
Faculty for High Quality Training
Course name: C Programming Language
Program name: ECET
Course ID: PRLA335164E
Signature of Proctor 1 Signature of Proctor 2
Exam code: 03 Number of pages: 9
Duration: 90 minutes.
One A4 sheet for notes is allowed.
Marks / Signature Student writes answers directly in space
reserved in exam paper and submit back all
exam papers.
Signature of Marker 1 Signature of Marker 2
Student name:

Student ID:

Exam number:.......... Exam room:

Question 1: Quiz 1 -20 (5/10): Choose the correct answer.


Quiz 1. In the C program, which of the following Quiz 2. What is the value of S after
statements is possible to enter an integer from the executing the following code:
keyboard and save it to an integer variable a? float c[8] = { 24 };
a. scanf("Enter value of a: %d",&a); int S;
b. scanf("%d",&a); S = sizeof(c);
c. scanf("Enter value of a: %d",a); a. Other answers
d. scanf("%d",a); b. 4
c. 24
d. 32
Answer #1: ……………. Answer #2: …………….
Quiz 3. In the C program, which of the following Quiz 4. What is the output of the following
statements is used to print value of an integer program:
variable a? #include <stdio.h>
a. printf ("value of a: %d", a); int main()
b. printf ("value of a: ", %d , a); {
c. printf ("value of a: %d , a"); char a[15] = "hello";
d. printf ("value of a: a", %d ); int S, i;
for (i = 0; i < 15;i++)
if (a[i] == '\0')
{
S = i;
break;
}
printf("%d", S);
getchar();
1
}
a. 5
b. 4
c. 15
d. 6
e. Other answers
Answer #3: ……………. Answer #4: …………….
Quiz 5. In the C language, how many bytes is the Quiz 6. What is the output of the following
variable a created with the following statement? program:
#include <stdio.h>
double a = 2; void main(void)
{
a. 2 byte int n = 8;
b. 10 byte while (n % 3 != 0)
c. 8 byte --n;
d. 4 byte printf("%d", n);
e. Other answers }
a. 5
b. 6
c. 8 7 6
d. 7
e. Other answers
Answer #5: ……………. Answer #6: …………….
Quiz 7. What is the output of the following program: Quiz 8. What is the output of the following
#include <stdio.h> program:
void main(void) #include <stdio.h>
{ void main(void)
int n = 4; {
do int n = 4;
{ for (n = 6; n > 1;n-=2)
printf("%d ", n--); {
} while (n > 0); printf("%d ", n--);
} }
}
a. Other answers a. 6 3
b. 3 2 1 0 b. 4 2
c. 4 3 2 1 c. 5 2
d. 4 d. Other answers
e. 0 e. 6 4 2

Answer #7: ……………. Answer #8: …………….


2
Quiz 9. What is the output of the following program: Quiz 10. What is the output of the following
#include <stdio.h> program:
void main(void) #include <stdio.h>
{ int hamc(int x);
int a = 1, b = 2, c = 3, d = 4, e = 5; void main(void)
if ((a <= b) && (b > c) || (d < e)) {
{ int a = 11, b = 8;
a = c - b; b = hamc(a);
a += e; printf("%d and %d", a, b);
e += a; }
d++;
d *= b; int hamc(int x)
++b; {
} ++x;
else return(x % 2);
{ }
b = a + c; a. 11 and 0
++a; b. 12 and 8
d = a + e; c. 11 and 9
c = b + d; d. Other answers
b--;
}
printf("%d, %d", a, b);
}
a. 3, 6 b. 6, 3 c. 63 d. Other answers
Answer #9: ……………. Answer #10: …………….
Quiz 11. What is the output of the following Quiz 12. What is the output of the following
program: program:
#include <stdio.h> int Func(int *a)
void main(void) {
{ if (*a>0)
int i = 0, c[] = { 1, 2, 3 }, b = *(c+1); {
switch (b) *a += 1; return 2;
{ }
case 1: i += 1; else
case 2: i = i + 2; break; {
case 3: i++; *a -= 1; return 3;
default: i += 3; }
} }
printf("%d", i); void main()
} {
3
int S = 1;
a. 1 S=Func(&S);
b. 2 printf("%d", S);
c. 3 }
d. Other answers a. -1
b. 1
c. 2
d. 3
e. Other answers
Answer #11: ……………. Answer #12: …………….
Quiz 13. What is the output of the following Quiz 14. What is the output of the following
program: program:
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <malloc.h>
void main(void) void main(void)
{ {
struct DIEMTHI int *a, S = 0, n = 3, i;
{ a = (int*)malloc(n*sizeof(int));
char c; for (i = 0; i < n; i++)
int d, d1, d2; *(a + i) = S + i;
} S = *(a + 2);
m = { 'C', 11, 2, 0 }; printf("%d", S);
m.d += 3; ++m.d2; }
printf("%c%d%d%d", m.c, m.d, m.d1, m.d2); a. Other answers
} b. 2
a. C1421 c. 0
b. C112 d. 1
c. 1421C e. 3
d. Syntax error
e. Other answers
Answer #13: ……………. Answer #14: …………….
Quiz 15. What is the output of the following Quiz 16. What is the output of the following
program: program:
#include <stdio.h> #include <stdio.h>
void func(int *n, int *m) int func(int k);
{ int main()
int a; {
a = *n - 9; *n = *m + 9; *m = a; int n=5, S;
} S = func(n);
void main(void) printf("%d", S);
{ return 0;
4
int i, a[4] = { 1, 3, 5, 7 }; }
func(&a[1], &a[2]); int func(int k){
printf("%d, %d", a[1], a[2]); int temp = 0;
} int j;
a. 14, -6 for (j = 1; j <= k; j++){
b. 15, -7 temp = temp + j;
c. 16, 9 }
d. Other answers return temp;
}
a. 15 b. 5 c. 1 d. Other answers
Answer #15: ……………. Answer #16: …………….
Quiz 17. What is the output of the following Quiz 18. What is the output of the following
program: program:
#include <stdio.h> #include <stdio.h>
int main() int main()
{ {
int a[10] = {1, 3, 2, 4, 5, 6, 45, 34, 23, 19}, hold; float a[5] = { 0, 1, 2, 3, 4};
for(int pass = 1; pass < 10; ++pass) { float *p1 = &a[1];
for (int i = 0; i < 9; ++i) { float *p2 = &a[3];
if (a[i] < a[i + 1]) { *(p1 - 1) = *p2 - 1;
hold = a[i]; *(p2 - 2) = 4;
a[i] = a[i + 1]; *(p1 + 1) = *p2 + 2;
a[i + 1] = hold; p1++;
} *(p1 + 1) = *p2 + 1;
} *(p2 + 1) = *p1;
} printf("%0.1f, %0.1f", a[1], a[2]);
printf("%d", a[0]); return 0;
return 0; }
} a. 4, 5
a. 10 b. 4.0, 5.0
b. 9 c. 2.0, 4.0
c. 1 d. 5.0, 4.0
d. 45 e. Other answers
e. Other answers
Answer #17: ……………. Answer #18: …………….
Quiz 19. What is the output of the following Quiz 20. What is the output of the following
program: program:
#include <stdio.h> #include <stdio.h>
void main(void) #include <malloc.h>
{ void main(void)
int a=10, b=3; double f; {
5
f=(double)a/(double)b; int *a, b;
printf("%2.2f",f); a = (int*)malloc(2 * sizeof(int));
} printf("%d ", a);
a. 3 }
b. 3.00 a. The address of variable a
c. 3.33 b. The address of variable b
d. Syntax error c. The size of the variable a
e. Other answers d. Other answers
Answer #19: ……………. Answer #20: …………….

Question 2: (1/10) Write one complete C program to do the following tasks:


a) A function which computes the factorial of a positive integer: k! = 1*2*…*k.
b) A main function which calls the above function to calculate the sum

where the positive integer n is entered from the keyboard.


.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
6
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................

Question 3: (2/10) Write one complete C program to do the following tasks:


a) Enter value for an integer array with 10 elements.
b) Find the largest value in the array.
c) Find the second largest value in the array.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Question 4: (2/10) Write one complete C program to do the following tasks:
a) Declare a structure for storing information for each student which has the following
members: Name (string), mathMark (integer), physicsMark (integer), chemicalMark (integer), and
averageMark (float).
b) By using an array of structures, store the information (Name, mathMark, physicsMark,
chemicalMark) of 10 students which is entered from the keyboard.
7
c) Calculate and store the average mark (averageMark) of 3 subjects (mathMark,
physicsMark, chemicalMark) for each student.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................

Note: Proctors are not allowed to give any unauthorised explaination.


Learning outcome mapping Assessed in
[G1.2, G1.3]: Present and apply the syntax and operation of statements Question 1
[G1.6]: Present the definition of C functions and use functions in a C program. Question 2
[G3.1]: Apply control structures, apply data manipulation, build support Questions 2,
functions to design and solve application programming requirements. 3, 4

02/01/2020
Approved by program chair
8

You might also like