0% found this document useful (0 votes)
6 views8 pages

FE Fall2023-24 Key

The document is a mid-term exam booklet for the ENGR104 Computer/Software program at Final International University, authored by Assist. Prof. Dr. Felix Babalola. It contains various coding problems, multiple-choice questions, and tasks related to C programming concepts, including code tracing, string functions, and loop conversions. The exam is structured into parts, with specific instructions for each section.

Uploaded by

citgezemirhan1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

FE Fall2023-24 Key

The document is a mid-term exam booklet for the ENGR104 Computer/Software program at Final International University, authored by Assist. Prof. Dr. Felix Babalola. It contains various coding problems, multiple-choice questions, and tasks related to C programming concepts, including code tracing, string functions, and loop conversions. The exam is structured into parts, with specific instructions for each section.

Uploaded by

citgezemirhan1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Assist. Prof. Dr.

Felix Babalola
Booklet A____________________________________________________January 29th, 2024

FINAL INTERNATIONAL UNIVERSITY • FACULTY OF ENGINEERING


COMPUTER/SOFTWARE PROGRAM
ENGR104 MID-TERM FALL 2023-2024

Instructor: Assist. Prof. Dr. Felix Babalola Name : .....……….....…………………


Duration: 75 min.
Number of pages: 8 pages Number : .....…………...……

Group Number: …..............…

Answer all the questions.

Part A: Trace the following snipets of code and give the correct OUTPUT
1)
int x= 5, y = 6, z = 7;
int funX(int x, int y){
return x > y ? x : y;
}

void funY(){
int x;
x = y - 2;
z = funX(x, y);
printf("x = %d, y = %d, z = %d \n", x, y, z);
}

int main(){
int y = 4;
funY();
printf("x = %d, y = %d, z = %d \n", x, y, z);
return 0;
}
x = 4, y = 6, z = 6
x = 5, y = 4, z = 6

2) #include <stdio.h>
int main(){
char *p = “FINAL EXAM”;
printf("%c\n", *(p + *p – 'E' + 2));
return 0;
}
A

-1-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

3)
int i = 1, x= 5, y = 10;
void funY(int A[], int x){
for(int i = 0; i< x; i++)
A[i] += y;
y += i;
}

int main(){
int arr[] = {1, 2, 3, 4, 5, 6};
funY(arr, 4);
for( ; i< x; i++)
printf("%d ", arr[i]);

printf("\n i = %d, x = %d, y = %d \n", i, x, y);


return 0;
}
12 13 14 5
i = 5, x = 5, y = 11

4)
int x= 5, y = 10;
int fun(int y){
--y;
return y * y;
}

int main(){

while(x > 0){


printf("%d ", fun(--x));
}
return 0;
}

94101

-2-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

5) int main(){
int D[3] = { 400, 401, 402 };
int C[3] = { 600, 601, 602 };
int i, *p1, *p2;
p1 = &D[0];
p2 = &C[0];
++p1;
++p2;

for (i = 1; i <= 2; i++) {


*p1 = *p1 +10;
*p2 = *p2 +5;
p1++;
p2++;
}
printf("%d %d %d\n \n", D[0], D[1], D[2]);
printf("%d %d %d\n", C[0], C[1], C[2]);
return 0;
}
400 411 412

600 606 607

Part B
1) Given the following initializations:

int numbers[ ] = {12, 14, 16, 18, 24, 28};


int *p = numbers;

Write down the values of the following expressions:

i) *p ………………12………………………

ii) *(p+3) …………………18………………………

iii) (p+1)–numbers ……………………1……………………

iv) (p[3] + 2) ……………………20……………………

v) numbers[5] - ++(*p) ……………………15……………………


-3-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

2) Given the following initializations


char s1[20] = “Soft ware”;
char s2[20] = “Computer”;
char s3[15] = “Artificial”;
char s4[15] = “Intelligence”

What will be the values of the following expressions?

i) printf(“%d”, strlen(s1)); …………………9…………………………

ii) printf(“%s”, strncpy(s3, s4, 3)); ………Intificial…………

i i i ) printf(“%s”, strncat(s3, “Engineering”,4)); …… IntificialEngi

iv) printf(“%d”,strcmp(s2,s3)); …………………-1……………………

v) printf(“%s”,strcpy(s1,s4)); …… Intelligence…

3) Write the elements of arrays A, B and C after the


declarations given below in the provided boxes:

a) int A[2][3] = {2, 4}; 2 4 0


0 0 0

b) int B[5] = {2, 4};


2 4 0 0 0

c) int C[3][3] = {{2, 4}, {2, 4}, {1}};

2 4 0
2 4 0
1 0 0

-4-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

Part C: Multiple choice questions (Each question is 3 pt)


1) What is the printf() statement that prints the output _ _ _ _53,_1220_41.1230 ?
( _ designates a space character)

a) printf("%-6d,%4d %.4f", 53,1220,41.123);

b) printf("%6d, %4d %.4f", 53,1220,41.123);

c) printf("%6d,%4d %.3f", 53,1220,41.123);

d) printf("%6d, %4d %f", 53,1220,41.123);

2) What values should be assigned to int variables x, y, and z below if the following C code
prints the output as 0 5 ?

int a, x=___, y=____, z=____ ; //make assignments here

a = x && y && z++;

printf("%d %d",a, z);

a) x = 1, y = 1, z = 4
b) x = 1, y = 1, z = 5
c) x = 1, y = 0, z = 4
d) x = 1, y = 0, z = 5

3) For which of the following, the code “G++;” will fail?

a) #define G 9.8

b) int G = 9.8;

c) float G = 9.8;

d) none of the above

4) Which statement should be inserted in the blank line below so that the C code displays the
output as 0 2 ?

int i = 0;

__________________ //blank line

printf("%d % d\n", x, y);

a) int x = ++i, y = ++i;


b) int x = i++, y = i++;
c) int x = ++i, y = i++;
d) int x = i++, y = ++i;

-5-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

5) What is the type of the following assignment expression if i is of type float and j is of type
int?

j=i+j

a) int b) float c) char d) double

6) What does the following C code do?

int x = 3, y, i, r = 0;

scanf("%d", &y);

for (i = 0;i < y; i++)

r += x;

a) It divides x by y
b) It multiples x by y
c) It adds x to y
d) It subtracts x from y

7) The output of the following partial C code is 30. Which statements can be inserted for line1
and line2 below?

int a=9, b=5, c=8;


a=b=c=10;

__________________ //Line 1

printf("1");
__________________ //Line 2

printf("2");
else
printf("3");
printf ("0");

a) Line1: if (a==10) && (b==5) Line 2: if (c==8)


b) Line1: if (a==9) Line 2: else if (b==5)
c) Line1: if (a==9) Line 2: if (b==5)
d) All of the above

-6-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

8) The output of the following C code is 4. Which of the following may be a possible input
series entered by the user?

int i, cnt=0;

for ( ; ; ) {

scanf("%d", &i);

if (i==0) break;

cnt++;

printf("%d", cnt);

a) 0, 4, 3, 2 b) 1, 5, 6, 4, 0 c) 2, 6, 3, 0 d) 3, 2, 1, 0, 0

Part D: Change the for loop in the following code to do loop


(10 marks)

int A[4] = {7, 8, 10, 5};


int tot=0;
for(int i = 3; i >= 0; i--){
tot = tot + A[i];
}
printf("The total is %d \n", tot);

..............................................................................................................................

................int i = 3; ...............................

................while( i >= 0) { ...........................................................

.................tot = tot + A[i]; .................................................

.................i --; ......................................................

...................} ....................................................

..............................................................................................................................

-7-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024

PRECEDENCE AND ASSOCIATIVITY

OPERATORS ASSOCIATIVITY

() [ ] -> . Left to right

! ++ -- + - * & (type) Right to left (Unary)

* / % Left to right

+ - Left to right

< <= > >= Left to right

== != Left to right

&& Left to right

|| Left to right

?: Right to left

= += -= *= /= %= Right to left

, Left to right

Some String Functions:


strlen(s1) Returns length of the string s1.
strcat( s1 , s2 )  Concatenates a copy of string s2 onto the string s1.
strncat(s1, s2, n)  Concatenates a copy of up to n characters from string s2 onto the string in s1.
strcpy(s1, s2)  Copies the string s2 to s1.
strncpy(s1, s2, n)  Copies a string up to n characters from s2 to s1.
strcmp(s1,s2)  Compares the strings s1 and s2, returning a value less than, equal to, or greater than 0,
depending on whether s1 is less than, equal to, or greater than s2.

-8-

You might also like