AMCAT COMPUTER PROGRAMMING PREVIOUS QUESTIONS (PAPERS) – 10

Ques32. Rohit writes the following program which inputs a number and prints “Double
digit” if the number is composed of two digits and “Not a double digit” if it is not.
int number;
if (number>10 AND number < 100)
print “Double digit”
else
print “Not a double digit”
end if
Rohit tries the following inputs: 5 and 66. The program works fine. He asks his
brother Ravi to try the program. When Ravi enters a number, the program doesn’t
work correctly. What did Ravi enter?
Op 1: 8
Op 2: 100
Op 3: 99
Op 4: 10
Op 5:
Correct Op : 4

Ques33. Rohan writes the following program which inputs a number and prints “Triple
digit” if the number is composed of three digits and “Not triple digit” if it is not.
int number;
if (number>99)
print “Triple digit”
else
print “Not triple digit”
end if
Rohan tries the following inputs: 25 and 566. The program works fine. He asks his
brother Ravi to try the program. When Ravi enters a number, the program doesn’t
work correctly. What did Ravi enter?
Op 1: 99
Op 2: 100
Op 3: 0
Op 4: 1000
Op 5:
Correct Op : 4

Ques34. Abhinav wants to find the largest number in a given list of 20 numbers. Which
of the following is an efficient approach to do this?
Op 1: Use bubble sort to sort the list in descending order and then print the first
number of the series.
Op 2: Use selection sort to sort the list in descending order and then print the first
number of the series.
Op 3: Implement one iteration of selection sort for descending order and print the
first number in the series.
Op 4: None of these
Op 5:
Correct Op : 3

Ques35. Lavanya wants to find the smallest number out of 26 inputted numbers. How
many minimum comparisons he has to make?
Op 1: 25
Op 2: 13
Op 3: 26
Op 4: 52
Op 5:
Correct Op : 1

Ques36. A company offers commission for selling it products to its salesperson. The
commission rate is Rs. 5 per product. However if the salesperson sells more than 200
items, he gets a commission of Rs. 10 on all items he sold after the first 200. Kanu
writes a program to calculate the commission for the salesperson:
integer numberProducts, commission
input numberProducts
if ( numberProducts > 200 )
— MISSING STATEMENT —
else
commission = numberProducts * 5
end if
print commission
Fill in the missing statement.
Op 1: commission = (numberProducts – 200) * 10
Op 2: commission = 200 * 5 + (numberProducts – 200) * 10
Op 3: commission = numberProducts * 10
Op 4: None of these
Op 5:
Correct Op : 2

Ques37. Vikram wants to write a program which checks whether the inputted number
is divisible by any of the first 6 natural numbers (excluding 1). He writes the following
efficient code for it.
int number, n = 2, isdivisible=0
input number
while ( n <=6) // Statement 1
{
if ( remainder (number, n) == 0)
isdivisible = 1
end
n = n+1 // Statement 2
}
if (isdivisible equals 1)
print “It is divisible”
else
print “It is not divisible”
end
Vikram takes the program to Hari. Hari tells Vikram that though the code is correct, it
can be made more efficient. Hari modifies a single statement and makes the code
more efficient. Which statement does he modify and how?
Op 1: Statement 1 is changed to:
while (n <=6 AND isdivisible=0)
Op 2: Statement 1 is changed to:
while (n <=6 OR isdivisible=0)
Op 3: Statement 1 is changed to:
while (isdivisible=0)
Op 4: Statement 2 is changed to:
n = n + 2
Op 5:
Correct Op : 1

Ques38. Rajiv wants to make a program which inputs two numbers: a and b (a>b)
and computes the number of terms between a and b (including a and b). What will
be code statement to do this:
Op 1: a – b
Op 2: a – b + 1
Op 3: a + b
Op 4: a – b – 1
Op 5:
Correct Op : 2

Ques39. I have a problem to solve which takes as input a number n. The problem has a
property that given the solution for (n-1), I can easily solve the problem for n. Which
programming technique will I use to solve such a problem?
Op 1: Iteration
Op 2: Decision-making
Op 3: Object Oriented Programming
Op 4: Recursion
Op 5:
Correct Op : 4

Ques40. What is the output of the following code statements? The compiler saves the
first integer at the memory location 4062. Integer is one byte long.
integer a
pointer b
a = 20
b = &a
print *b
Op 1: 4062
Op 2: 4063
Op 3: 20
Op 4: 10
Op 5:
Correct Op : 3

Ques41. What is the output of the following code statements? The compiler saves the
first integer at the memory location 4165 and the rest at consecutive memory spaces
in order of declaration. Integer is one byte long.
integer a, b
pointer c, d
a = 30
c = &a
b = *c
a = a + 10
print b
Op 1: 30
Op 2: 4165
Op 3: 40
Op 4: 4166
Op 5:
Correct Op : 1