# AMCAT Previous Years Questions on Computer Programming:Iteration, Recursion, Decision

### Number of Questions: 26 || Module Duration: 22 min

 Topics Sub- Topics Expected Questions Basic Programming 10 – 12 Questions Data Structures 6 – 8 Questions OOPs Polymorphism 4 – 6 Questions Miscellaneous 4 – 5 Questions

Predict the output of the questions –
Function main() {
double d = 123.4
static float f =123.4
if (m equals i)
print ”Both of them are equal”
else if( f > d )
print ”Float is greater”
else
print ”Double is greater”
}
A. Float is greater
B. Double is greater
C. Both of them are equal
D. Code will generate error

equals is not a function to compare float and double

Question 2
As a project, Parag wants to write a code which should increment its value until a condition is satisfied. Which type of structure should he be using?
A. For
B. While
C. Do while
D. Perforate

Do while is exactly what the questions says for loop does the same thing but not in the exact scenario as the question

Question 3
Predict the output of the following code int p = 1256, q ,r, s=10; q=p/s; r=p-q; print r;
A. 126
B. 1131
C. 125.6
D. 1130.6

1256/10 = 125 1256 – 125 = 1131

Question 4
function foo() {
int a = 0;
switch(a) {
case 0 : print “2”;
case 2 : print “2”;
case 4 : print “2”;
}
A. nothing gets printed
B. 2
C. 2
D. 222

222 will be printed as there is no break anywhere

Question 5
Predict the output of the following Code
function foo()
{
int a= 245,b=5, d;
d = a/b
switch(d)
{
case 4 :print “I behaved correctly”
break
case 49:print “I behaved with accuracy”
break
default:print “Not Sure”
}
}
A. I behaved correctly
B. I behaved with accuracy
C. Not Sure
D. Error

Break doesn’t have – ;

Question 6
Which of the following is used to iteratively do the same thing again and again with auto feeding values?
A. For Loop
B. do while
C. if
D. Recursion

Only recursion feeds value to it again and again in other loops we have to write code to iterative values with i++ or i= i-2 etc.

Question 7
Predict the output of the following – #include int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf(“%d “, fun(2)); return 0; }
A. 2
B. 8
C. 16
D. 32

Fun(2) | 2*fun(3) | 2*fun(4) | 4 After tree evaluation we get 16 So, C is the correct answer

Question 8
What will be the output of following program ? #include int main( ) { int a=300,b,c; if(a>=400) b=300; c=200; printf(“%d,%dn”,b,c); return 0; }
A. Garbage value, Garbage Value
B. 300,200
C. 200,300
D. Garbage value,200