0% found this document useful (0 votes)
74 views15 pages

Pseudo Code

Uploaded by

goyiyew212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views15 pages

Pseudo Code

Uploaded by

goyiyew212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

COMPANY SPECIFIC SERIES

PSEUDOCODE - TRAINER HANDOUT

1. What will be the output of the following pseudocode for a = 3, b = 8?


Integer funn(Integer a, Integer b)
if(b mod a < 2)
b = b >> 1
return a
End if
if(a mod b < 2)
b = b + 12
return b
end if
return a + b + 5
End function funn()
a.4 b. None of these c. 16 d. 12
Answer: c. 16

2. What will be the value of the following pseudocode?


Integer value, n, num
Set value = 1, n = 45
num = num >> 1
num = num + value
Print num
a. 44 b. 0 c. 1 d. 12
Answer: c. 1

3. What will be the value of the following pseudocode?


Integer j, m
Set m = 1, j = 1
Integer a[3] = {0,1,4}
if (a[m - 1] || (a[-1] && a[1]))
a[j] = 5
End if
m = m + a[j]
Print m
a. 3 b. 4 c. 6 d. 2
Answer: c. 6
4. What will be the value of the following pseudocode for x = 27?

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

5. What will be the value of the following pseudocode?


Integer x,y
for(each x from 1 to 11)
x=x+2
end for
Print x
a. 11 b. 10 c. 12 d. 13
Answer: d. 13

6. What will be the value of the following pseudocode?


Input f = 6, g = 9 and set sum = 0
Integer n
if (g > f)
for (n = f; n<g; n=n+1)
sum = sum + n
End for loop
else
Print Error Message
Print sum
a.6 b. 21 c. 15 d. 9
Answer: b. 21

7. What will be the value of the following pseudocode?


Integer j, m
Set m = 1, j =1
Integer a[3] = {0, 1, 0}
a[0] = a[0] + a[1]
a[1] = a[1] + a[2]
a[2] = a[2] + a[0]
if(a[0])
a[j] = 5
End if
m = m = a[j]

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

9. What will be the value of the following pseudocode for k=150?


fun(integer k)
if(k>155)
return
end if
print k
fun(k+2)
print k
End of function fun( )
a. 150 152 154 b. 150 152 154 154 152 150 c. 150 d. None of the mentioned
Answer: b. 150 152 154 154 152 150

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

11. What will be the output of the following pseudocode?


Integer a, n, b
Set a = 0, n = 0, b
for(each n from 0 to 4)
n=n+1

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

12. What will be the output of the following pseudocode?


Integer a[5], b[5], c[5], k, l
Set a[5] = {5, 9, 7, 3, 1}
Set b[5] = {2, 4, 6, 8, 10}
for(each k from 0 to 4)
c[k] = a[k] - b[k]
end for
for(each 1 from 0 to 4)
Print c[1]
end for
a. 7 13 13 11 11 b. 3 5 1 -5 -9 c. -3 -5 -1 5 9 d. None
Answer: b. 3 5 1 -5 -9

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

14. What will be the output of the following pseudocode for a = 3?


void fun(int a)
if(a<1)
return
else
print a
fun(a-2)
print a
return
End function fun( )
a. 2 1 1 2 b. 1 2 c. 2 1 0 d. 3 1 1 3

4
Answer: d. 3 1 1 3

15. What will be the output of the following pseudocode?


Integer p, q r
Set q = 13
for(each p from 1 to 4)
r = q mod p
p=p+5
q=p+r
end for
r = q/5
Print q, r
a. 6 4 b. 1 3 c. 7 2 d. 6 1
Answer: d. 6 1

16. What will be the output of the following pseudocode?


Integer x
Set x = 259
if(x EQUALS 0)
Print "0"
otherwise if(x MOD 9 EQUALS 0)
Print "9"
otherwise
Print x MOD 9
end if
a. 8 b. 16 c. 7 d. None
Answer: c. 7

17. What will be the output of the following pseudocode?


Integer a[5], b[5], c[5], k, l
Set a[5] = {1, 2, 3, 4, 5}
Set b =[5] = {6, 7, 8, 9, 10}
for(each k from 0 to 4)
c[k] = a[k] + b[k]
end for
Print c[1]
end for
a. 11 12 13 14 15 b. None c. 7 8 9 10 11 d. 7 9 11 13 15
Answer: d. 7 9 11 13 15

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

19. What will be the output of the following pseudocode?


Integer j, m
Set m = 1, j = 1
Integer a[5] = {6, 4, 3, 1, 4}
if(a[m - 1])
a[j] = a[j] + 5
End if
m = m + a[j]
Print m
a.10 b. 9 c. 8 d. 4
Answer: a. 10

20. What will be the output of the following pseudocode?


Integer j, m
Set m = 4
Integer a[4] = {4, 13, 2, 1}
for{each j from 0 to 3}
if(j > 1)
m = m + a[j]
End if
if(j > 2)
Continue
End if
m=m+1
End for
Print m
a. 8 b. 10 c. 1 d. 4
Answer: b. 10

21. What will be the output of the following pseudocode?


Integer a, b, count, count1
Set a = 1, b = 1
while(a <= 5)
b=1
while(b <= 5)
b=b+1
count1 = count1 + 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

23. What will be the output of the following pseudocode?


Integer a, b
Set a = 12, b = 25
a = (a + b) MOD 2
b=b=a
a = a + b - 13
Print a, b
a. -11 1 b. -12 00 c. 11 22 d. 37 24
Answer: a. -11 1

24. What will be the output of the following pseudocode?


Integer i
Set i = 0
Start : i = 12
Print i
if(i < 60)
goto Start
else
Print i + 1
end if
a. 0 12 0 12 13 b. 12 24 36 48 60 61 c. 12 infinite times d. 0 12 24 25
Answer: c. 12 infinite times

25. What will be the output of the following pseudocode?


Integer y1, y2
Set y1 = 8, y2 = 8
do

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

26. What will be the output of the following pseudocode?


Integer a, b, c
Set b = 10, a = 1
for(each c from 1 to 3)
a = (a + c) * c
b=b-c
End for
if (0 && 1 && (2^3))
b=a-1
a=a-1
a=b+1
a = a >> 1
b = b >> a
Else
a=b+1
b=a-1
a=a-1
End if
Print a + b
a.7 b. 3 c. 4 d. 8
Answer: d. 8

27. What will be the output of the following pseudocode?


Integer a, b, c
Set a = 4, b = 4 , c = 4
if(a & (b ^ b) & c)
a = a >> 1
End if
Print a + b + c
a. 16 b. 24 c. 8 d. 12
Answer: d. 12

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

29. What will be the output of the following pseudocode for a = 5, b = 1?


Integer funn(Integer a, Integer b)
if((b + a || a - b) && (b > a) && 1)
a=a+b+b-2
return 3 - a
Else
return a - b + 1
End if
return a + b
End function fun( )
a. 0 b. 5 c. 16 d. 11
Answer: b. 5

30. What will be the output of the following pseudocode for a = 5, b = 3?


Integer funn(Integer a, Integer b)
if((b mod a > a mod b) || (a ^ b > a))
a=a^b
if(a)
b=1
return 4^5^6
End if
return 1^2^3
End if
return a+b
End function funn ( )
a.7 b. 9 c. 16 d. 3
Answer: a. 7

31. What will be the output of the following pseudocode for a = 5, b = 1?


Integer funn(Integer a, Integer b)
if((b mod a && a mod b) || (a ^ b > a))
a=a^b
Else
return a - b
End if
return a + b
End function funn( )
a. -9 b. 5 c. 6 d. 21
Answer: b. 5

32. What will be the output of the following pseudocode a = 1, b = 3?

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

33. What will be the output of the following pseudocode for a = 4, b = 8?


Integer funn(Integer a, Integer b)
if(a > b)
b=b^a
End if
if(b > a)
a=a^b
End if
return a + b
End function funn ( )
a. 35 b. 20 c. 14 d. 25
Answer: b. 20

34. What will be the output of the following pseudocode?


Integer x
Set x = 2
if(x is EQUAL TO 1)
if(x IS EQUAL TO 0)
Print "A"
else
Print "B"
end if
else
Print "C"
end if
a. B C b. C c. A d. B
Answer: b. C

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

36. What will be the output of the following pseudocode?


Integer a, b
Set b = 2
for(each a from 1 to 6)
a=a+2
b=b+a-4
end for
Print b
a.3 b. 4 c. 1 d. 8
Answer: a. 3

37. What will be the output of the following pseudocode?


Integer value, n
Set value = 1, n = 45
while(value less than equal to n)
value = value << 1
end loop
Print value
a. 64 b. 32 c. None d. 45
Answer: a. 64

38. What will be the output of the following pseudocode?


Integer j, m
Set m = 1
Integer a[4] = {1, 0, 1, 1}
for(each j from 0 to 1)
if(j > 2)
Continue
Else
if(a[j])
m = a[j]
End if
End if
End for
Print m
a.5 b. 8 c. 1 d. 7
Answer: c. 1

39. What will be the output of the following pseudocode?

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

40. What will be the output of the following pseudocode?


Integer a, b, c
Set a = 4, b = 2, c = 3
if(a || a & b || a & b & c)
c=1
a=c^1
Else
c=1
b=b^3
End if
Print a + b + c
a.4 b. -1 c. 3 d. 23
Answer: c. 3

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

2. What will be the output of the following pseudocode?


Integer a, b, c
Set a = 4, b = 1, c = 2
if(b ^ (c & a) && a ^ (c & b))
c=a+a
a=c+c
Else
c= b + b
b=c+c
End if

12
Print a + b + c
a. 22 b. 31 c. 34 d. 25
Answer: d. 25

3. What will be the output of the following pseudocode?


Integer a, b, c
Set a = 1, b = 2
for(each c from 4 to 6)
a=a^b
if(c - a < b + a)
b=2
a=1
Jump out of the loop
End if
a=a^c
End for
Print a + b
a. -2 b. 8 c. 3 d. 16
Answer: c. 3

4. What will be the output of the following pseudocode?


Integer a, b, c
Set a = 2, b = 1
for(each c from 1 to 5)
if(c > 3 || b > 3)
a=a+c
End if
b=b-1
b=b+a
End for
b=b+1
Print a + b
a. 30 b. 33 c. 31 d. 37
Answer: c. 31

5. What will be the output of the following pseudocode?


Integer a, b, c
Set a =4, b = 1, c = 2
if(b ^ (c & a) && a ^ (c & b))
c=a+a
a=c+c
Else
c=b+b
b=c+c
End if

13
Print a + b + c
a. 22 b. 31 c. 34 d. 25
Answer: d. 25

6. What will be the output of the following pseudocode for a = 6, b = 7?


Integer funn(Integer a, Integer b)
if(a < b && a > 0)
a = a + 10
if(a > 0 && b> 0 )
a=a^b
End if
a = a >> 1
End if
return a + b
End function funn( )
a. 27 b. 14 c. 18 d. 20
Answer: c. 18

7. What will be the output of the following pseudocode?


Integer a, b
Set b = 8
Set a = b
Print a // line 4
a = a + b - 10
if(a > 0)
Go to line 4
End if
a. 8 8 8 0 b. 6 4 2 0 c. 8 6 4 2 d. 8 4 2
Answer: c. 8 6 4 2

8. What will be the output of the following pseudocode?


Integer a, b
Set a = 20, b = 4
while (a >= b)
a = a >> 1
end while
Print a
a.2 b. 3 c. 4 d. 5
Answer: a. 2

9. What will be the value of s if n = 127?


Read n
i=0,s=0
Function Sample(int n)
while (n>0)

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.

10. What will be the value of s if N=20?


Read N
Function sample(N)
s = 0, f = 1, i=1;
Do Until i <= N
f = f * i;
s = s +(i / f);
i = i+1
End Do
return(s);
End Function
a. 666667 b. infinite loop c. 708333 d. 716667
Answer: b. infinite loop
Solution: This code will never end because the value of n is never been updated.

15

You might also like