AMCAT Computer Science Questions with Answers - 4

AMCAT Computer Programming Previous Years Question answers with Solutions 4

Ques90. 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
Op 5:
Correct Op : 1

Ques91. 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
Op 5:
Correct Op : 2

Ques92. 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
Op 5:
Correct Op : 4

Ques93. 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
Op 5:
Correct Op : 3

Ques94. 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
Op 5:
Correct Op : 2

Ques95. 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
Op 5:
Correct Op : 2

Ques96. 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
Op 5:
Correct Op : 1

Ques97. 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
Op 5:
Correct Op : 2

Ques98. Assuming n > 2, What value does the following function compute for odd n?
function 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 + 3 + 5 + 7 + ... + n
Op 3: n/2 + (1 + 3 + 5 + 7 + ... + n)
Op 4: 1 + (1 + 3 + 5 + 7 + ... + n)
Op 5:
Correct Op : 2

Ques99. 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
Op 5:
Correct Op : 4

Ques100. 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
Op 5:
Correct Op : 3

Ques101. 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
Op 5:
Correct Op : 1

Ques102. 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.
Op 5:
Correct Op : 4

Ques103. 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
Op 5:
Correct Op : 3

Ques104. Which of these is not a data type?
Op 1: integer
Op 2: character
Op 3: boolean
Op 4: array
Op 5:
Correct Op : 4

Ques105. 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
Op 5:
Correct Op : 1

Ques106. 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
Op 5:
Correct Op : 2

Ques107. 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
Op 5:
Correct Op : 2

Ques108. There are two loops which are nested. This implies which one of the following?
Op 1: Two loop, one after the other
Op 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
Op 5:
Correct Op : 2

Ques109. How will 47 be stored as an unsigned 8-bit binary number?
Op 1: 10111101
Op 2: 00101111
Op 3: 10111000
Op 4: 00101101
Op 5:
Correct Op : 2

Ques110. An integer X is saved as an unsigned 8-bit number, 00001011.What is X?
Op 1: 22
Op 2: 11
Op 3: 10
Op 4: None of these
Op 5:
Correct Op : 2

Ques111. A variable cannot be used…
Op 1: Before it is declared
Op 2: After it is declared
Op 3: In the function it is declared in
Op 4: Can always be used
Op 5:
Correct Op : 1

Ques112. What is implied by the argument of a function?
Op 1: The variables passed to it when it is called
Op 2: The value it returns on execution
Op 3: The execution code inside it
Op 4: Its return type
Op 5:
Correct Op : 1

Ques113. Which of the following is true about comments?
Op 1: They are executed only once.
Op 2: They are not executed
Op 3: A good program does not contain them
Op 4: They increase program execution time.
Op 5:
Correct Op : 2

Ques114. Neelam wants to share her code with a colleague, who may modify it. Thus
she wants to include the date of the program creation, the author and other
information with the program. What component should she use?
Op 1: Header files
Op 2: Iteration
Op 3: Comments
Op 4: Preprocessor directive
Op 5:
Correct Op : 3

Ques115. Shashi writes a program in C++ and passes it on to Pankaj. Pankaj does some
indentation in some statements of the code. What will this lead to?
Op 1: Faster Execution
Op 2: Lower memory requirement
Op 3: Correction of errors
Op 4: Better readability
Op 5:
Correct Op : 4

Ques116. Zenab and Shashi independently write a program to find the the mass of one
mole of water, which includes mass of hydrogen and oxygen. Zenab defines the
variables:
integer hydrogen, oxygen, water // Code A
while Shashi defines the three quantities as:
integer a, b, c // Code B
Which is a better programming practice and why?
Op 1: Code B is better because variable names are shorter
Op 2: Code A is better because the variable names are understandable and nonconfusing
Op 3: Code A will run correctly, while Code B will give an error.
Op 4: Code B will run correctly, while Code A will give an error.
Op 5:
Correct Op : 2

Ques117. For solving a problem, which of these is the first step in developing a working
program for it?
Op 1: Writing the program in the programming language
Op 2: Writing a step-by-step algorithm to solve the problem.
Op 3: Compiling the libraries required.
Op 4: Code debugging
Op 5:
Correct Op : 2

Ques118. A robust program has which one of the following features?
Op 1: It runs correctly on some inputs
Op 2: It is robust to hardware damage
Op 3: It can handle incorrect input data or data types.
Op 4: None of these
Op 5:
Correct Op : 3

Ques119. Tarun wants to write a code to divide two numbers. He wants to warn the user
and terminate the program if he or she enters 0 as the divisor. Which programming
construct can he use to do this?
Op 1: Iteration
Op 2: Decision-making
Op 3: Recursion
Op 4: None of these
Op 5:
Correct Op : 2

Ques120. To solve a problem, it is broken in to a sequence of smaller sub-problems, till a
stage that the sub-problem can be easily solved. What is this design approach called?
Op 1: Top-down Approach
Op 2: Bottom-Up Approach
Op 3: Procedural Programming
Op 4: None of these
Op 5:
Correct Op : 1

No comments:

Post a Comment