DEPARTMENT OF MATERIAL AND ENGINEERING DESIGN FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING UNIVERSITI TUN HUSSEIN ONN MALAYSIA (UTHM), JOHOR TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013 Student Name Matrix Number Section :. :. :. THIS TEST PAPER HAS 9 PRINTED PAGES
1. What is the output of following for loop source code? a. This is a for loop -5-4 -3-2 -1 0 b. This is a for loop -5-4 -3-2 -1 0 1 c. This is a for loop -6-5 -4-3 -2-1 0 d. This is a for loop -6-5 -4-3 -2-1 #include<conio.h> int main(void){ int k; printf("this is a for loop\n"); for(k = -6; k <= 0; k = k +1) {printf("%d ", k);} getch(); return 0; } 2. What is the output of the following code? a. :Yes Sir! Rightaway Sir!: : Yes Sir! R: b. :Yes Sir! R: : Yes Sir! R: c. :Yes Sir! R: :Yes Sir! R : d. :Yes Sir! Rightaway Sir!: :Yes Sir! R : main(){ printf(":%-10s:\n", "Yes Sir! Rightaway Sir!"); printf(":%15.10s:\n", " Yes Sir! Rightaway Sir!"); getch(); } 3. What is the output of the following code? a. 5.1 005 b. 0.0 0005 c. 5.1 0005 d. 0.0 005 main(){ float a,b; int c,d; a = 15.3; b = a/3; printf("%.1f\n",b); c = 20; d = c/4; printf("%03d\n",d); getch(); }
4. Which of the definition is correct? a. char int; b. int long; c. int width; d. float double; 5. What will be the output for the program? a. 6 b. 6.0 c. 6.000000 d. Error: prototype sqrt() not found #include<math.h> int main() { printf("%f\n", sqrt(36.0)); return 0; } 6. How many times will Chukoku be printed? a. 0 times b 5 times c. 10 times d Infinite times int main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("chukoku"); } return 0; } 7. What is the value of x after the following statement? float x; x = 3.0 / 4.0 + 3 + 2 / 5; a. 4.15 b. 5.75 c. 1.75 d. 3.75
8. What is the correct way to write the condition c < r < z? a. (c< r< z) b. ( (c< r) && z) c. ((c> r) (c < z)) d. ((c < r) && (r< z)) 9. If x is 0, what is the value of (!x ==0)? a. false b. true c. unable to determine d. 1 10. Which of the following cannot be checked in a switch-case statement? a. character b. float c. integer d. All of the above 11. Which of the following are valid case statements in a switch? a. case 1: b. case x<4: c. case abc : d. case 1.5: 12. int r[3][4]; will have how many element in the array? a. 7 b. 12 c. 9 d. 16 13. Which of the following is correct for = and ==? e. = use in conditional operation while == use in mathematical operation. f. = and == used in program representing equal. g. == use only in conditional operation while = in mathematical operation. h. = and == is a type of function.
14. int array[a][b]; what is a and b represent? a. [Colums][rows] ; b. [data] [Colums]; c. [rows] [Colums]; d. [Colums][size]; 15. for(int item=0;item<=35;item+=5) How many times the coding will execute the statement inside { } a. 7 b. 8 c. 9 d. 6 16. Which of the following statement fits the following equation a. temp= (4* pow(t,2)/(t+2))-20; b. temp= 4* pow(t,2)/((t+2)-20); c. temp= 4*t*t/((t+2)-20); d. temp= (4*t*t)/t+2-20; 17. Choose the correct output for a. 2 3 b. 1 2 c. 1 3 d. 2 4 int a = 1; printf("%d\t",a++); printf("%d\n",++a); 18. Which is incorrect statement related to #define a. #define is use for macros b. #define use to define constant value c. #define can only use for PI (e.g: #define PI 3.142) d. #define is a global declaration for constant value
19. Which are valid identifier/variable: a. BTI 10202 b. school c. void d. 123abc 20. Which of the following is NOT one of the standard C data type? a. double b. byte c. int d. char 21. What is the output for the following code? int a = 1; int b = 2; int c = 3; a=c; c=b; b=a; printf( %d %d %d, a,b,c); a. 3 2 1 b. 1 3 3 c. 3 3 2 d. 2 3 1 22. What is the output for the following code? float x = 1 / 2; printf( %f, x); a. 0.000000 b. 0.500000 c. 1.000000 d. 0
23. Consider the following two lines of output. abc def Which of the following code will produce exactly this output? a. printf( abc\ndef ); b. printf( abc ); printf( def ); c. printf( abc\n ); printf( \n ); printf( def\n ); d. printf( abc ); printf( ); printf( def ); 24. Consider the following conditional statement if (!( (a < b) (b == c) ) ) { printf( success ); } What values for a,b and c would result in success being printed out to the screen? a. int a = 20; int b = 20; int c = 20; b. int a = 10; int b = 20; int c = 30; c. int a = 30; int b = 20; int c = 20; d. int a = 20; int b = 20; int c = 30;
25. Which of the following C expression does not evaluate to 7? a. 1 + 2 * 3 b. 17 % 10 c. (int) 6.6 + (int) 0.5 d. 15 / 2 26. What output is produced by the following code? float a = 1.9; float b = 1.8; int c = (int) (a + b); printf( %d, c); a. 1 b. 2 c. 3 d. 4 27. What output is produced by the following code? int a = 10; float b = 16; float c = b / a; printf( %f, c); a. 1 b. 1.000000 c. 1.600000 d. %f 28. What output is produced by the following code? int a = 5 % 9; int b = 9 % 3; printf( %d %d, a, b); a. 4 6 b. 4 0 c. 5 6 d. 5 0
29. Which line of code should replace????? below to correctly calculate the average of x and y and PRODUCE 3.500000 as output? float average; int x = 3; int y = 4;????? printf( %f, average); a. average = (x+y) / 2; b. average = x / 2 + y / 2; c. average = (x + y) / 2.0; d. average = x + y / 2.0; 30. Consider the following while loop int i = 0; while ( i < 3) { printf( %d \n, i); i++; } Which for loop below produces DIFFERENT output to the while loop above? a. int i; for (i = 0; i < 3; i++) { printf( %d\n, i); } b. int i; for (i = 3; i >= 0; i--) { printf( %d\n, (3 - i)); } c. int i; for (i = 0; i <= 2; i++) { printf( %d\n, i ); } d. int i; for (i = 1; i < 4; i++) { printf( %d\n, (i 1)); }