Name

:

Student ID:

COM142 – C Programming
Spring 2009-2010 Computer Engineering Department Near East University

Midterm Exam
April 27, 2010 [11:30A] Lecturer: Hüseyin Sevay

INSTRUCTIONS
You have 100 minutes for this exam. This exam is worth a total of 105 points, and points above 100 are bonus. This question paper has 5 single-sided pages (except for this title page) and a total of 12 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 remaining page NOW ! Each question specifies how many points it is worth. 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.

COM142 – C Programming – Midterm Exam (Spring 2009-2010) Student ID: 1. Provide a single GNU/Linux command that would create an executable from this source file. fileB. [5 points] 4. [5 points] PLEASE DO NOT WRITE IN THIS SPACE ! Page 1 of 5 .o created from the C source file named project. and meaning of each variable you use.c. assuming it needs no external libraries.c. types.” into a proper conditional statement in C. Provide a GNU/Linux command that would compile (but not link) this source file: [5 points] 2.c. Provide a GNU/Linux command to link this object file into an executable. Suppose you have a C source file named program. Provide a GNU/Linux command that would display on the screen the result of just preprocessing this source file. [5 points] 5.c that you longer have access to. State the names. Suppose you have a C source file named hw. Kyrenia. [5 points] 6. Provide all the GNU/Linux commands that you would need to create an executable named proj from these source files. Suppose you are working on a project that involves three (3) C source files named fileA.c.c that calls Math library functions.c . and write the condition as an if-statement with an empty body. and main. [5 points] 3. project. Suppose you have an object file. Convert the English statement ”An old woman living in Nicosia. Suppose you have a C source file named hw. or Famagusta who has at least two children.

PLEASE DO NOT WRITE IN THIS SPACE ! Page 2 of 5 . What value will the following program print out? Show all your computations step by step. printf( "%d\n". result -= 2 * z % 13 + y / 3 + x. Write down the output that will be produced by the following program. y=17. printf( "%d\n". return i. return( 0 ). m=40. int i=10. j=20. Write down the output of the following program. printf( "%d\n". [15 points] #include <stdio. if ((f(i) < f(k)) && (f(j) >= f(m))) {} printf( "\n" ). } /* end main */ 8. printf( "%d\n".h> int main( void ) { int x=2. i-. (i++ + 10) ). } int g( char c ) { printf( "%c ". if ((g(c1) != g(c3)) && (g(c1) == g(c2))) {} printf( "\n" ). } /* end main */ (--i + 3) ). k=30. if ((g(c1) > g(c2)) && (g(c1) > g(c3))) {} return 0. [15 points] #include <stdio. if ((f(i) < f(j)) || (f(k) >= f(m))) {} printf( "\n" ).). z=11.h> int main( void ) { int i=3. s2[]="Hello". return c. i ). } /* end main */ 9.COM142 – C Programming – Midterm Exam (Spring 2009-2010) Student ID: 7.h> int f( int i ) { printf( "%d ". c2=’a’. ++i ). i += i. printf( "%d\n". char c1=’A’. c ). printf( "%d\n". c3=’B’. result=5. return 0. if ((s1 == s2) || (f(j) >= f(k)) || (g(c1) == g(c3))) {} printf( "\n" ). result ). [10 points] #include <stdio. } int main( void ) { char s1[]="Hello". i ).

that returns the sum of the following series for n terms: [10 points] x2 x3 x4 xn + + +···+ 2 3 4 n ser i es(x. int n). n) = x + PLEASE DO NOT WRITE IN THIS SPACE ! Page 3 of 5 . Write a C function with the prototype double series( double x.COM142 – C Programming – Midterm Exam (Spring 2009-2010) Student ID: 10.

COM142 – C Programming – Midterm Exam (Spring 2009-2010) Student ID: 11. your program should work as follows: [10 points] % . Write a complete C program that counts the number of even and odd integers provided from the command line./count Number of Number of 3 5 7 9 even values: odd values : 2 2 4 4 5 even values: odd values : 0 4 4 1 even values: 0 odd values : 0 PLEASE DO NOT WRITE IN THIS SPACE ! Page 4 of 5 . For example./count Number of Number of % . assuming the executable of your program is named count./count Number of Number of % .

then your program should print out the message: *** Please enter some values. • Example 1: If your program is provided the input values 4 2 3 from the command line. Do not assume a fixed number of input values! Your program should work with any number of input values. • Example 3: If your program is provided no input values. PLEASE DO NOT WRITE IN THIS SPACE ! Page 5 of 5 . your program should work as follows: [15 points] • Note that input should be read from the command line. then your program should print out the message: The average is 5. Assuming the name of your program is is avg. Write a complete C program that computes the average of the floating-point values entered as argument at the command line and prints out the result as shown below.COM142 – C Programming – Midterm Exam (Spring 2009-2010) Student ID: 12. • Example 2: If your program is provided the input values 1 2 3 4 5 8 12 from the command line. then your program should print out the message: The average is 9.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.