Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

HCMC National University

International University
------------

Final Examination
Date: 19th August 2019
Duration: 120 minutes

SUBJECT: C/C++ Programming in UNIX


Approval Lecturer:
Signature Signature

Full name: Full name:

Proctor 1 Proctor 2
Signature Signature

Full name: Full name:

STUDENT INFO
Student name:

Student ID:

INSTRUCTIONS:
Open-note exam. You can bring any hand-written notes. No laptops/PCs/PDAs are allowed.
Write your answer on this exam paper CLEAN and TIDY.
Return this paper after you finish.
HCMC National University International University
Student ID:…………………………….
------------

PART I (20 pts): Write your answer in the given blank spaces
30384. (5 pts) What does the following program do? }
#include <stdio.h> Answer:
#define SIZE 10
int whatIsThis( const int b[], int p );
int main( void ){
int x; 30386. (5 pts) What is the output of the following
int a[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
x = whatIsThis( a, SIZE ); program?
printf( "Result is %d\n", x ); #include <stdio.h>
return 0; int main( void ){
} int a[] = { 10, 20, 30, 40 }, i;
int whatIsThis( const int b[], int p ){ int *aPtr = a;
if ( p == 1 ) { for ( i = 0; i < 4; i++ ) {
return b[ 0 ];
} printf( "%d ", a[i] );
else { printf( "%d ", aPtr[i]);
return b[ p - 1 ] + whatIsThis( b, p - 1 ); printf( "%d\n", *(aPtr+i));
} }
} return 0;
Answer: }
Answer:

30385. (5 pts) What is the output of the following


program? 30387. (5 pts) Find the error in the following program
#include <stdio.h> and explain how to correct it:
#define SIZE 5 #include <stdio.h>
void myFunction( int b[], int size ); void printNum( const int *numPtr );
int main( void ){ int main( void ){
int i, a[ SIZE ] = { 0, 1, 2, 3, 4 }; int a = 5;
myFunction( a, SIZE ); printNum(&a);
for ( i = 0; i < SIZE; i++ ) { return 0;
printf( "%3d", a[ i ] ); }
} void printNum( const int *numPtr ){
return 0; *numPtr = 10;
} printf("%d", *numPtr);
void myFunction( int b[], int size ){ }
int j; Answer:
for ( j = 0; j < size; j++ ) {
b[ j ] *= 2;
}

PART II (80pts): Write your solutions in the given blank spaces. Just need to provide ONLY the main part of the
programs or functions, input/output can be ignored. Choose four in five follow questions.
1. (20 pts) Bubble sort.
a) (05 pts) Write a C function to swap two integers using call by reference (pointer).
b) (05 pts) Write the bubble sort algorithm using above swapping function to sort an array in descending order.
c) (10 pts) Write a C program / function that implements the algorithm in b).
2. (20 pts) Prime number.
a) (10 pts) Write the algorithm to check if a number is a prime number.
b) (10 pts) Write a C function that implements above algorithm.
3. (20 pts) Eigenvalue and eigenvector. A number a and a non-zero vector v satisfying Av = av are called
eigenvalue and an eigenvector of square matrix A, respectively.
a) (10 pts) Write the algorithm to check if a and v are eigenvalue and eigenvector, respectively, of a given matrix A.
b) (10 pts) Write a C function that implements above algorithm.
4. (20 pts). Strings.
a) (10 pts) Write the algorithm to check if string str1 is contained in str2. (Don’t use substring function.)
b) (10 pts) Write a C function / program that implements above algorithm.
5. (20 pts). Frequency of characters.
a) (10 pts) Write the algorithm to count frequency of each character in a string.
b) (10 pts) Write a C function / program that implements above algorithm.

Answer:

2/5
HCMC National University International University
Student ID:…………………………….
------------

3/5
HCMC National University International University
Student ID:…………………………….
------------

4/5
HCMC National University International University
Student ID:…………………………….
------------

THE END.

5/5

You might also like