Post Page Advertisement [Top]

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


Question 1
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

Correct Answer: D

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

Correct Answer: C

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

Correct Answer: B

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

Correct Answer: D

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

Correct Answer: D
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

Correct Answer: D
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
Integer a = 20, b =10, c = 20, d =10 Print a*b/c-d Print a*b/(c-d) Will the output be same for the two ?
A. The output will have a difference of 20
B. Will be same
C. Cant be said depends on compiler
D. differ by 100


Correct Answer: A


Question 8
Predict the output of the following – #include <stdio.h> 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

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


Question 9
What will be the output of following program ? #include<stdio.h> 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

Correct Answer: D
As the condition within the if statement is false so the value of b will not be initialized so it will print the garbage value and c is initialized to 200 so the output will be Garbage,200


Question 10
What will be the output of code ? #include<stdio.h> int main( ) { int x=3,y,z; y=x=10; z=x<10; printf(“x=%dy=%dz=%dn”,x,y,z); return 0; }
A. 10,10,10
B. 10,10,0
C. 0,0,0
D. 0,10,10

Correct Answer: B

Bottom Ad [Post Page]

| Designed by Colorlib