AMCAT COMPUTER PROGRAMMING PREVIOUS QUESTIONS (PAPERS) – 13

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

Ques68. Ravi is writing a program in C++. C++ uses the ‘for’ keyword for loops. Due to
distraction, Ravi writes ‘gor’ instead of ‘for’. What will this result to?
Op 1: The code will not compile.
Op 2: The code will give an error while in execution
Op 3: The code may work for some inputs and not for others.
Op 4: It will create no problems.
Op 5:
Correct Op : 1

Ques69. What does a compiler do?
Op 1: Converts code from a high level language to a low level language
Op 2: Necessarily converts the code into assembly language
Op 3: Converts code from a low level language to a high level language
Op 4: Necessarily converts the code into machine language
Op 5:
Correct Op : 1

Ques70. A program is compiled by Tarun on his machine. Whether it will run on a
different computer will depend upon:
Op 1: Operating system on the computer
Op 2: Hardware configuration of the computer
Op 3: Both operating system and hardware configuration
Op 4: The language of the program
Op 5:
Correct Op : 3

Ques71. Sakshi writes a code in a high-level programming language on a Pentium-III
machine, which she wants to execute on a Motorola chip. What of the following will
she run on the code?
Op 1: An interpreter
Op 2: A compiler
Op 3: A cross-compiler
Op 4: Linker
Op 5:
Correct Op : 3

Ques72. Shahaana has a 10,000 line code. She is trying to debug it. She knows there is a
logical error in the first 25 lines of the code. Which of the following will be an
efficient way of debugging:
Op 1: Compile the whole code and step into it line by line
Op 2: Use an interpreter on the first 25 lines.
Op 3: Compile the whole code and run it
Op 4: None of these
Op 5:
Correct Op : 2

Ques73. Farhan writes a code to find the factorial of an inputted number. His code
gives correct answer for some inputs and incorrect answers for others. What kind of
error does his program have?
Op 1: Syntactical error
Op 2: Run-time Error
Op 3: Logical Error
Op 4: None of these
Op 5:
Correct Op : 3

Ques74. Reshama is debugging a piece of code which takes several iterations of
modifying and executing code, while Mohammad has to deliver a product to the
customer, which the customer will run multiple times. Reshama wants her debug
cycle to take minimum possible time, while Mohammad wants that his products run
time is minimum. What tools should Reshama and Mohammad respectively use on
their code?
Op 1: Compiler, Interpreter
Op 2: Interpreter, Compiler
Op 3: Compiler, Compiler
Op 4: Interpreter, Interpreter
Op 5:
Correct Op : 2

Ques75. Gautam writes a program to run on a Motorola processor on his Pentium
computer. He wants to see how the program will execute on the Motorola processor
using his Pentium machine. What tool will he use?
Op 1: Compiler
Op 2: Interpreter
Op 3: Assembler
Op 4: Simulator
Op 5:
Correct Op : 4