Pseudo Code
Pseudo Code
1
Integer fun(Integer x)
if(x > 9)
fun(x/9)
Print x - 1
fun(x/3)
else
print x - 2
end if
end function fun()
a. 1 26 7 b. 26 7 1 c. 9 8 2 d. 7 80 1
Answer: a. 1 26 7
2
Print m
a. 3 b. 2 c. 6 d. 4
Answer: c. 6
8. Which of the following options is correct for the given code for n = 39 and r = 13?
Integer f1(Integer n, Integer r)
if(n > 0)
return (n - r + f1(n/3, 13))
else
return 0
end if
End function f1 ()
a. 3 b. 0 c. 5 d. 1
Answer: c. 5
10. Which of the following is the most appropriate option for the output of the given pseudocode for n = 25?
Integer foo(Integer n)
if(n EQUALS 1)
return 1
else if((n MOD 2) EQUALS 0)
return n*2
else
return foo(n - 10/3)
end if
End function foo( )
a. 20 b. 44 c. 15 d. 25
Answer: b. 44
3
if(n EQUALS 3)
Print "Hello World"
end if
Jump out of the loop
End for
Print n
a.2 b. 1 c. 3 d. Hello World
Answer: b. 1
13. How many times "A" will be printed in the following pseudocode?
Integer a, b, c
for(a = 0 to 4)
for(b = 0 to 2)
if(a is greater than b)
Print "A"
End if
End for
End for
a. 8 b. 7 c. 9 d. 10
Answer: c. 9
4
Answer: d. 3 1 1 3
18. Which of the following output is correc for the given code if n = 64?
Integer large(Intger n)
if(n <=1)
return 1
end if
5
if(n mod 4 EQUALS 0)
return large(n/4)
end if
return large(n/4) + large(n/4 * 1)
End function large( )
a.1 b. 0 c. 6 d. 4
Answer: a. 1
6
end while
a=a+1
count = count + 1
end while
Print count, count 1
a. 25 5 b. 24 5 c. 5 25 d. 5 5
Answer: c. 5 25
22. What will be the output of the following pseudocode a=2, b=2?
Integer funn(Integer a, Integer b)
if(a & b > 0)
return 1 + funn(a - 1, b) + funn(a, b - 1)
End if
return 0
End function funn( )
a. 0 b. 2 c. 4 d. 9
Answer: a. 0
7
print y1/y2
while(y1/y2)
end do while
a. It will print 1 infinite time b. 8 c. 0 d. 1
Answer: a. It will print 1 infinite time
28. What will be the output of the following pseudocode for a = 10, b = 11?
Integer funn(Integer a, Integer b)
if(0)
return a - b - funn(-7, -1)
End if
a=a+a+a+a
return a
8
End function funn( )
a. 40 b. 30 c. 44 d. 0
Answer: a. 40
9
Integer funn(Integer a, Integer b)
if(a&1 && 1)
return funn(a-1, a+a) + funn(a-1, b+b)
Else
return b^a
End if
a.8 b. 26 c. 1 d. 15
Answer: a. 8
35. What will be the output of the following pseudocode for input 7?
Read the value of N.
Set m = 1, T = 0
if(M>N) // line 3
Go to line no. 9
else
T=T+m
m=m+1
10
Go to line no. 3
Print T // line 9
a. 76 b. 32 c. 56 d. 28
Answer: d. 28
11
Integer a, b, c
Set a = 4, b = 0, c = 0
if(a)
a = a << 1
End if
b = b ^ (c >> 1)
Print a + b + c
a.11 b. 5 c. 8 d. 18
Answer: c. 8
EXTRA QUESTIONS
1. What will be the output of the following pseudocode?
Integer a, b, c
Set a = 5, b = 5, c = 9
if((b && (c >> 1)) || (b && (c << 1)))
a = a^ 1
End if
Print a + b + c
a. 18 b. 27 c. 14 d. 19
Answer: a. 18
12
Print a + b + c
a. 22 b. 31 c. 34 d. 25
Answer: d. 25
13
Print a + b + c
a. 22 b. 31 c. 34 d. 25
Answer: d. 25
14
r = n%l0
p = 8^i
s = s+p*r
i++
n = n/10
End While
return s;
End Function
a. 27 b. 187 c. 87 d. 120
Answer: c. 87
Solution: The following code is converting an octal number into its decimal representation. Here we are
treating 127 as an octal input and converting it into its decimal representation that is 87.
15