This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Computer Programming – Set 3
Number of Questions: 25
Module Duration: 35 min
Detailed Syllabus:
Basic Programming
•Data Types•Iteration, Recursion, Decision•Procedure, functions and scope
Ques 1. Consider the following code: function modify(w,u) {
w = w + 2 u = u - 3 return (w - u)
} function calculate( ) {
integer a = 10, b = 20, c c = modify(a, b); print a print space print b
} Assume that a was passed by value and b was passed by reference. What will be the output of the program on executing function calculate( ) ? Op 1: 12 17 Op 2: 10 17 Op 3: 12 20 Op 4: 10 20
Ques 2. Which one of the following is the lowest level format to which the computer converts a higher language program before execution? Op 1: English code Op 2: Machine Code Op 3: Assembly Language Op 4: System Language
Correct Option of Ques 1 Op 2: 10 17
Ques 3. If you want to write a function that swaps the values of two variables, you must pass them by:Op 1: Value only Op 2: Reference only Op 3: Either A or B Op 4: Neither A nor B
Correct Option of Ques 2 Op 2: Machine Code
Ques 4. Consider the following code: if (condition 1) {
if (condition 2) { // Statement A } else if (condition 3) { // Statement B } else { // Statement C }
}else if (condition 4) { // Statement D
} else { // Statement E}
}Which of the following conditions will allow execution of statement C? Op 1: condition1 AND condition3 Op 2: condition1 AND condition4 AND !condition2 Op 3: NOT(condition2) AND NOT(condition3) Op 4: condition1 AND NOT(condition2) AND NOT(condition3)
Correct Option of Ques 3 Op 2: Reference only
Ques 5. What does the following function do? function operation (int a, int b) {
if (a < b) { return operation(b, a) } else { return a }
} Op 1: Returns the max of (a,b) Op 2: Returns the min of (a,b) Op 3: Loops forever Op 4: Always returns the second parameter
Correct Option of Ques 4 Op 4: condition1 AND NOT(condition2) AND NOT(condition3)
Ques 6. What does the following function do? function operation (int a, int b){
if (a > b) { return operation(b, a) } else { return a; }
} Op 1: Always returns the first parameter Op 2: Returns the min of (a,b) Op 3: Returns the max of (a,b) Op 4: Loops forever
Correct Option of Ques 5 Op 1: Returns the max of (a,b)
Ques 7. function g(int n) { if (n > 0) return 1; else return -1;
} function f(int a, int b) {
if (a > b) return g(b-a); if (a < b) return g(a-b); return 0;
} If f(a,b) is called, what is returned? Op 1: Always -1Op 2: 1 if a > b, -1 if a < b, 0 otherwise Op 3: -1 if a > b, 1 if a < b, 0 otherwise Op 4: 0 if a equals b, -1 otherwise
Correct Option of Ques 6 Op 2: Returns the min of (a,b)
Ques 8. function g(int n) { if (n > 0) return 1; else return -1;
} function f(int a, int b) {
if (a > b) return g(a-b); if (a < b) return g(b-a); return 0;
} If f(a,b) is called, what is returned? Op 1: 1 if a > b, -1 if a < b, 0 otherwise Op 2: Always +1 Op 3: 0 if a equals b, +1 otherwise Op 4: -1 if a > b, 1 if a < b, 0 otherwise
Correct Option of Ques 7 Op 4: 0 if a equals b, -1 otherwise
Ques 9. function g(int n) { if (n > 0) return 1; else return -1;
} function f(int a, int b){
if (a > b) return g(a-b); if (a < b) return g(-b+a); return 0;
} If f(a,b) is called, what is returned? Op 1: Always +1 Op 2: 1 if a > b, -1 if a < b, 0 otherwise Op 3: -1 if a > b, 1 if a < b, 0 otherwise Op 4: 0 if a equals b, -1 otherwise
Correct Option of Ques 8 Op 3: 0 if a equals b, +1 otherwise
Ques 10. function g(int n) { if (n > 0) return 1; else return -1;
} function f(int a, int b) {
if (a > b) return g(b-a); if (a < b) return g(-a+b); return 0; }
If f(a,b) is called, what is returned? Op 1: Always +1 Op 2: -1 if a > b, 1 if a < b, 0 otherwise Op 3: 1 if a > b, -1 if a < b, 0 otherwise Op 4: 0 if a equals b, -1 otherwise
Correct Option of Ques 9 Op 2: 1 if a > b, -1 if a < b, 0 otherwise
Ques 11. function g(int n) { if (n > 0) return 1; else return -1;
} function f(int a, int b) {
if (a > b) return g(b-a); if (a < b) return g(-a+b); return 0;
} If f(a,b) is called, what is returned? Op 1: Always +1 Op 2: -1 if a > b, 1 if a < b, 0 otherwise Op 3: 1 if a > b, -1 if a < b, 0 otherwise Op 4: 0 if a equals b, -1 otherwise
Correct Option of Ques 10 Op 2: -1 if a > b, 1 if a < b, 0 otherwise
Ques 12. Consider the following code: for i= m to n increment 2 {
print "Hello!" } Assuming m < n and exactly one of (m,n) is even, how many times will Hello be printed? Op 1: (n - m + 1)/2 Op 2: 1 + (n - m)/2 Op 3: 1 + (n - m)/2 if m is even, (n - m + 1)/2 if m is odd Op 4: (n - m + 1)/2 if m is even, 1 + (n - m)/2 if m is odd
Correct Option of Ques 11 Op 2: -1 if a > b, 1 if a < b, 0 otherwise
Ques 13. Consider the following code: for i= m to n increment 2 {
print "Hello!" } Assuming m < n and (m,n) are either both even or both odd, How many times will Hello be printed?Op 1: (n - m + 1)/2 Op 2: 1 + (n - m)/2 Op 3: 1 + (n - m)/2 if m is even, (n - m + 1)/2 if m is odd Op 4: (n - m + 1)/2 if m is even, 1 + (n - m)/2 if m is odd
Correct Option of Ques 12 Op 1: (n - m + 1)/2
Ques 14. Assuming n > 2, What value does the following function compute for odd n? function f (int n) {
} Op 1: 1 + 2 + 3 + 4 + ... + n Op 2: 1 + 3 + 5 + 7 + ... + n Op 3: n/2 + (1 + 3 + 5 + 7 + ... + n) Op 4: 1 + (1 + 3 + 5 + 7 + ... + n)
Correct Option of Ques 13 Op 2: 1 + (n - m)/2
Ques 15. Assuming n > 2, What value does the following function compute for even n? int f (int n) {
if (n equals 1) { return 1 } if (n equals 2) { return f(n-1) + n/2 } return f(n-2) + n
} Op 1: 1 + 2 + 3 + 4 + ... + n Op 2: 1 + (2 + 4 + 6 + 8 + ... + n) Op 3: 1 + n/2 + (4 + 6 + 8 + ... + n) Op 4: 2 + 4 + 6 + 8 + ... + n
Correct Option of Ques 14 Op 2: 1 + 3 + 5 + 7 + ... + n
Ques 16. The for loop is equivalent to a while loop when Op 1: There is no initialization expression Op 2: There is no increment expression Op 3: A and B combined are true Op 4: It is never equivalent
Correct Option of Ques 15 Op 4: 2 + 4 + 6 + 8 + ... + n
Ques 17. Consider the statement while (a < 10.0) {
a = a*a } Assuming a is positive, for what value of a will this code statement result in an infinite loop? Op 1: a < 1.0 Op 2: a < sqrt(10) Op 3: a > sqrt(10) Op 4: a = 0
Correct Option of Ques 16 Op 3: A and B combined are true
Ques 18. int area(double radius) { return PI*radius*radius;
} Which of the following is always true about the function area? Op 1: It returns the area of a circle within the limits of double precision.Op 2: It returns the area of a circle within the limits of the constant PI. Op 3: It returns the area of a circle within the limits of precision of double, or the constant PI, whichever is lower. Op 4: None of the above.
Correct Option of Ques 17 Op 1: a < 1.0
Ques 19. What does this function compute for positive n? function f(int n) {
if (n equals 1) { return 1
} else { return f(n-1)/f(n-1) + n
} } Op 1: 1 + n Op 2: 1 + 2 + 3 + ... + n Op 3: 1 + n, if n > 1, 1 otherwise Op 4: None of the above
Correct Option of Ques 18 Op 4: None of the above.
Ques 20. Which of these is not a data type? Op 1: integer Op 2: character Op 3: boolean Op 4: array
Correct Option of Ques 19 Op 3: 1 + n, if n > 1, 1 otherwise
Ques 21. The construct "if (condition) then A else B" is for which of the following purposes? Op 1: Decision-Making Op 2: Iteration Op 3: Recursion Op 4: Object Oriented Programming
Correct Option of Ques 20 Op 4: array
Ques 22. In a sequential programming language, code statements are executed in which order? Op 1: All are executed simultaneously Op 2: From top to bottom Op 3: From bottom to top Op 4: None of these
Correct Option of Ques 21 Op 1: Decision-Making
Ques 23. A for-loop is used for which of the following purposes? Op 1: Decision-Making Op 2: Iteration Op 3: Recursion Op 4: None of these
Correct Option of Ques 22 Op 2: From top to bottom
Ques 24. There are two loops which are nested. This implies which one of the following? Op 1: Two loop, one after the otherOp 2: Two loops, one inside the others Op 3: One loop with two different iteration counts Op 4: Two loops with the same iteration count
Correct Option of Ques 23 Op 2: Iteration
Ques 25. How will 47 be stored as an unsigned 8-bit binary number? Op 1: 10111101 Op 2: 00101111 Op 3: 10111000 Op 4: 00101101
Correct Option of Ques 24 Op 2: Two loops, one inside the others