20091_final - Dept. of Computer Eng. Student Name & Surname...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Dept. of Computer Eng. Fall 2009 CEng 230 Final Examination Jan. 12, 2010 75 Minutes EXAM GROUP A Student Name & Surname Student ID Use the below program to answer next 2 questions. int days_in_feb(int y) { if(y % 100 == 0) return 28; if(y % 4 == 0) return 29; return 28; } int dyear ( int day , int month, int year ){ int day_of_year ; day_of_year = day ; for( ; month > 0; month--) switch ( month ) { case 11: case 9 : case 6: case 4 : day_of_year += 30; break; case 10: case 8 : case 7: case 5 : case 3: case 1 : day_of_year += 31; break; case 2: day_of_year += days_in_feb( year ); } return day_of_year ; } 1. What is the value returned by dyear(1,3,2009)? a) 1 b) 32 c) 60 d) 91 e) 30 2. There is an error in this program. Which of the below corrections would fix this error? a) switch (month) switch(month -1) b) for(; (month-1)>0 ; month--) for(; (month-1) > 0 ;) c) return 28 return ( (month == 2)? 28:29) d) switch (month) switch(month +1) e) There is no error. 3. What is the value of “y” after below code segment is executed? int x1 = 7, x2 = 10, x3 = 8.1, y ; y = x3>x1 – x2<=10 ; a) 0 b) 1 c) 1.0 d) 0.0 e) Invalid assignment 4. What is the output of the below code? #include <stdio.h> int fun (int ix){ ix = ix * 2 ; printf ("%d " , ix); return ix ; } int main (void) { int x = 3 ; printf ("%d ", x); printf ("%d\n", fun(x)); return 0 ; } a) 3 6 6 b) 3 3 3 c) 3 6 3 d) 3 6 9 e) 3 3 6 5. What is the output of the below program with input “3” #include<stdio.h> int fonksiyon ( int gln ) { if( gln <= 1 ) return 1; else return (gln*fonksiyon(gln– 1)); } int main ( void ) { int k,N,f; puts(“Enter an integer: “); scanf ( “ %d “ , &N ); f= fonksiyon(N); printf(“Result is=%d\n“, f ); return 0 ; } a) 1 b) 2 c) 3 d) 4 e)5 6. What is the mistake in the below switch statement? double a= 1.25; switch(a){ case 1.1: case 1.2: x= x*x; y= x; break; case 1.3: y= x*x; case 2.1: case 3.3: y= sqrt(x); break; case 3.5: printf(“Error “); break; default: y= x+1; a) “case 1.3” has no break b) “default” doesn’t have “printf” c) “a = 1.25” is not matched. d) “switch” works only with integers e) “case 3.5” doesn’t need “break”
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
7. How can you code the below condition in C? “x and y are both greater than z” a) a) x > z && y > z b) b) x && y > z c) c) (x && y) > z d) d) (x | | z ) > z e) e) x > z | | y > z 8. If a=1 and b=20 what is the output of the below code segment? if(a=10){ if(b == 20) printf(“*** ”); } else printf(“*****”) ; a) *** b) ***** c) *** ***** d) No Output is produced e) * * * * * * * * * 9. What is the effect of the following code segment? int i; for (i=1;i <21;i++) if (i%3 == 0) printf(“%4d”,i); a) It prints out the multiples of 3 from 3 to 21 b) It prints out the multiples of 3 from 1 to 18 c) It prints out the odd numbers from 3 to 18 d) It prints out the multiples of 3 from 3 to 18 e) It prints out the odd numbers from 3 to 21 10. What are the values of k and m after the following segment has been executed? k=1;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/09/2010 for the course COMPUTER E 5710230 taught by Professor Assoc.prof.dr.cemhüseyinbozşahin during the Spring '09 term at Middle East Technical University.

Page1 / 8

20091_final - Dept. of Computer Eng. Student Name & Surname...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online