AMCAT Previous Years Questions on Miscellaneous : Procedure, functions and scope

Topics
Sub- Topics
Expected Questions


Basic Programming


10 - 12 Questions


Data Structures



6 - 8 Questions


OOPs



4 - 6 Questions

Miscellaneous


4 - 5 Questions


Ques63. Saumya writes a code which has a function which calls itself. Which
programming concept is Saumya using?
Op 1: This is bad programming practice and should not be done.
Op 2: Recursion
Op 3: Decision Making
Op 4: Overloading
Op 5:
Correct Op : 2

Ques64. Shrishti writes the code for a function that computes the factorial of the
inputted number n.
function factorial(n)
{
if(n equals 1)
return 1
else
-- MISSING STATEMENT --
end
}
Fill in the missing statement.
Op 1: return factorial(n-1)
Op 2: return n*factorial(n)
Op 3: return n*(n-1)
Op 4: return n*factorial(n-1)
Op 5:
Correct Op : 4

Ques65. Tanuj writes the code for a function that takes as input n and calculates the
sum of first n natural numbers.
Function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
Fill in ?? in the code.
Op 1: n equals 1
Op 2: n equals 2
Op 3: n >= 1
Op 4: n > 1
Op 5:
Correct Op : 1

Ques66. Saloni writes the code for a function that takes as input n, an even integer and
calculates the sum of first n even natural numbers.
function sum( n )
{
if(n equals 2)
return 2
else
return (n + sum(n-2))
end
}
She then calls the function by the statement, sum(30). How many times will the
function sum be called to compute this sum.
Op 1: 1
Op 2: 30
Op 3: 15
Op 4: 16
Op 5:
Correct Op : 3

Ques67. Consider the following function
function calculate( n )
{
if(n equals 5)
return 5
else
return (n + calculate(n-5))
end
}
Shishir calls the function by the statement, calculate(20). What value will the
function return?
Op 1: 50
Op 2: 200
Op 3: 35
Op 4: 20
Op 5:
Correct Op : 1


Ques76. Consider the following code:
function modify(y,z)
{
y = y + 1;
z = z + 1;
return y - z
}
function calculate( )
{
integer a = 5, b = 10, c
c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by value. What will be the output on executing
function calculate( )?
Op 1: 11 -5
Op 2: 10 -5
Op 3: 6 -5
Op 4: 5 -5
Op 5:
Correct Op : 4

Ques77. Consider the following code:
function modify(b,a)
{
return a - b
}
function calculate( )
{
integer a = 5, b = 12, c
c = modify(a, b);
print c
}
Assume that a and b were passed by reference. What will be the output of the
program on executing function calculate( ) ?
Op 1: 7
Op 2: -7
Op 3: Error
Op 4: 8
Op 5:
Correct Op : 1

Ques78. Consider the following code:
function modify(y,z)
{
y = y + 1
z = z + 1
return y - z
}
function calculate( )
{
integer a = 12, b = 20, c
c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by reference. What will be the output of the
function calculate( ) ?
Op 1: 12 -8
Op 2: 13 -8
Op 3: 12 8
Op 4: 13 8
Op 5:
Correct Op : 2

Ques79. Afzal writes a piece of code, where a set of three lines occur around 10 times
in different parts of the program. What programming concept can he use to shorten
his program code length?
Op 1: Use for loops
Op 2: Use functions
Op 3: Use arrays
Op 4: Use classes
Op 5:
Correct Op : 2

Ques80. Geetika writes a piece of code, where a set of eight lines occur around 10
times in different parts of the program (Code A). She passes on the code to Deva.
Deva puts the set of eight lines in a function definition and calls them at the 10
points in the program (Code B). Which code will run faster using an interpreter?
Op 1: Code A
Op 2: Code B
Op 3: Code A and Code B will run with the same speed
Op 4: None of these
Op 5:
Correct Op : 1

Ques81. Consider the following code:
function modify(a,b)
{
integer c, d = 2
c = a*d + b
return c
}
function calculate( )
{
integer a = 5, b = 20, c
integer d = 10
c = modify(a, b);
c = c + d
print c
}
Assume that a and b were passed by value. What will be the output of the function
calculate( ) ?
Op 1: 80
Op 2: 40
Op 3: 32
Op 4: 72
Op 5:
Correct Op : 2

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

Ques83. Consider the following function:
function run( )
{
integer a = 0 // Statement 1
while (a < 5)
{
integer c = 0 // Statement 2
c = c + 1 // Statement 3
a = a + 1
}
print c // Statement 4
}
At which statement in this program will the compiler detect an error?
Op 1: Statement 1
Op 2: Statement 2
Op 3: Statement 3
Op 4: Statement 4
Op 5:
Correct Op : 4



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

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

Ques88. 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 E?
Op 1: condition1 AND condition3
Op 2: NOT(condition1) AND condition2 AND NOT(condition4)
Op 3: NOT(condition2) AND NOT(condition3)
Op 4: condition1 AND condition4 AND NOT(condition2) AND NOT(condition3)
Op 5:
Correct Op : 2

Ques89. 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 condition will allow execution of statement A?
Op 1: NOT(condition2) AND NOT(condition3)
Op 2: condition1 AND condition4 AND NOT(condition2) AND NOT(condition3)
Op 3: condition1 AND condition2 AND condition4
Op 4: NOT(condition1) AND condition2 AND NOT(condition4)
Op 5:
Correct Op : 3

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

No comments:

Post a Comment