COM142 - C Programming Final Exam
COM142 - C Programming Final Exam
COM142 - C Programming Final Exam
COM142 – C Programming
Fall 2009-2010
Computer Engineering Department
Near East University
Final Exam
January 12, 2010 [11:30A]
Lecturer: Hüseyin Sevay
INSTRUCTIONS
This exam is worth a total of 111 points, and points above 100 are bonus.
This question paper has 9 single-sided pages (except for this title page) and a total of 19 questions. Please check
to make sure you have all the pages NOW !
Please write your name and student ID in the boxes at the top of this page and your student ID on each of the
remaining question pages NOW !
Please write your answers in the allotted space/box(es) below or next to each question. Do not write your
answers anywhere else! Especially please do not write below the footer line on question pages.
Read each question carefully, and do not start answering a question before understanding what that question
is asking for.
Student ID:
COM142 – C Programming – Final Exam (Fall 2009-2010)
1. Suppose you have a C source file named account.c . Provide a GNU/Linux command that would compile
this source code into object code: [2 points]
2. Suppose you have a C source file named grades.c . Provide a GNU/Linux command that would compile and
link this code with the Math Library into an executable named grades: [2 points]
3. During which stage of building an executable are directives such as #define and #ifdef processed by a C
compiler? Name the stage. [2 points]
4. Suppose are given an object file named main.o. In order, name the stage/stages of building an executable that
this file has to be put through in order to generate an executable from it. [2 points]
5. What will the following program print out when run? [12 points]
7. What will the following program print out when run? Show how you computed the results of each operation.
[5 points]
9. Write a C function named printRange that, when called, prints out all integers between two given values a
and b, assuming a « ∆ b, where a should be the first argument to the function and b the second argument
to the function. For example, if the call printRange( 1, 10000 ) is executed, this call should print out the
sequence 1 2 3 4 5 . . . 9998 9999 10000 . [5 points]
• Input should be read from the command line, not from the keyboard directly!
• Example 1: If your program is provided the input values 1 2 3 4 , then your program should print out
the message:
The average is 2.50
• Example 2: If your program is provided the input values 1 2 3 4 5 6 12 , then your program should
print out the message:
The average is 5.00
• Example 3: If your program is provided no input values, then your program should print out the following
message and exit:
*** Please provide some values.
• Hint 1: atof()
• Hint 2: argv, argc
12. Consider the function named reverse that reverses a given string in the following program. Fill in the six (6)
blanks to complete the implementation of reverse. [6 points]
#include <stdio.h>
#include <string.h>
14. Write a C function that accepts a 1-dimensional floating-point array and its size as argument and returns the
average of the values in that array. [5 points]
16. Suppose you have the following integer array where the indices are shown below the array. Show how the
Bubble Sort algorithm would sort this array in ascending order. Show the result of each pass and all critical
steps within each pass. [5 points]
7 6 5 9 3 0 8 4 2 1
0 1 2 3 4 5 6 7 8 9
7 6 5 9 3 0 8 4 2 1
0 1 2 3 4 5 6 7 8 9
18. In C, implement the Ackermann function whose definition is given below. Your function should have the
prototype int Ackermann( int m, int n ); [10 points]
8
< n≈ 1 if m ∆ 0
A(m, n) ∆ A(m ° 1, 1) if m » 0 and n ∆ 0
:
A(m ° 1, A(m, n ° 1)) if m » 0 and n » 0
struct node {
int value;
struct node *next;
}
Assuming this declaration, write just the necessary C code in order to dynamically create the structure given in
the figure below. [10 points]
5 7 2
lst