Top 50 Pseudo Code Questions and Answers

Most Asked Pseudo Code Questions and Answers

This article brings you the Top 50 most asked pseudo code questions with solutions, carefully selected to help you prepare for various pseudo code interview questions and placement tests. If you are a beginner or someone looking to improve your pseudo code practice, this collection will help you understand how to approach different types of problems and build strong pseudo code solving skills.

Whether you’re wondering what is pseudo code, or looking for practical examples to enhance your preparation, this guide covers a wide range of commonly asked problems in technical assessments.

most asked pseudo code questions with solution

What is Pseudo?

Prime Course Trailer

Related Banners

Ready to practice?

Below are the Top 50 Pseudo Code Problems with Solutions to help you prepare effectively for pseudo code interviews and placement rounds.

Most Asked Pseudo Code Questions with Solutions

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Top 50 Pseudo Code Questions with Solutions

Top 50 Pseudo Code Questions and Answers

Pseudo Code Problems Set 1

1. What will be the value of a,b,c?

a=50, b=23
c = a + b
c = c mod b
b = b + c
a = a - b
print a,b,c

23, 27, 4

23, 27, 4

92.22%

23, 17, 3

23, 17, 3

4.44%

77, 27, 4

77, 27, 4

2.22%

69, 19, 4

69, 19, 4

1.11%

Explanation:
c = 50 + 23 = 73
c = 73 % 23 = 4
b = 23 + 4 = 27
a = 50 - 27 = 23
Thus, a = 23, b = 27, c = 4.

2. What will be the value of m?

p = [1,1,0,1,7]; m=0
if p[0] && p[4]:
  m = p[1]
if p[2] && p[3]:
  m = p[2]
print m

18

18

5.62%

1

1

89.89%

-5

-5

1.12%

4

4

3.37%

Explanation:
p[0] && p[4] = true → m=1; p[2] and p[3] = (0 &&1)=false → m remains 1.

3. What will be the value of m?

a = [3,0,1,0,2]; m = –1
for j from 0 to 4:
  if a[j] & j:
    a[j] = a[j] & j
m = a[0] + a[4] – a[1]
print m

15

15

4.94%

4

4

12.35%

5

5

79.01%

8

8

3.7%

Explanation:
Only positions where bitwise AND non-zero update; compute accordingly → gives 5.

4. What will be the value of m?

a = [10,11,3,2]; m = 0
for j = 0 to 3:
  if j > 0:
    a[j] = a[j‑1] + 2
m = a[0] + a[2] + a[1]
print m

52

52

1.37%

41

41

13.7%

36

36

69.86%

29

29

15.07%

Explanation:
a[1]=12, a[2]=13, a[3]=15 → m =10+13+12 =35? Options maybe off. Based on that output, closest is 41 if numbers differ. Adjust: a[1]=10+2=12; a[2]=12+2=14; sum =10+14+12=36 → C.

5. What will be the value of i?

i = 0
while (+ (+ i‑‑) != 0):
  i = i + 5
print i

5

5

21.33%

4

4

6.67%

-1

-1

66.67%

2

2

5.33%

Explanation:
+ is dummy; loop condition while(i-- != 0) is false immediately but i post-decrements to ‑1 which is printed.

6. What will be the output?

function func(n):
  i = 0
  while n % 10 != 0:
    n = n + 3
    i = i + 1
  n = n ‑ i
  return n
print func(35)

50

50

5.71%

55

55

5.71%

53

53

4.29%

45

45

84.29%

Explanation: n steps: 35→38→41→44→47→50 (i=5); then return 50‑5 = 45.

7. What will be the value of j?

static count = 0
func(no):
  count = count + no
  return count
for i = 0 to 5:
  j = func(i)
print j

18

18

4.55%

15

15

87.88%

20

20

3.03%

25

25

4.55%

Explanation:
cumulative sum: 0+1+2+3+4+5 =15.

8. How many "A" printed?

for a = 0 to 4:
  for b = 0 to 2:
    if a > b: print "A"

8

8

10.61%

7

7

9.09%

9

9

37.88%

10

10

42.42%

Explanation:
Count pairs where a > b: for a=0 none; a=1: b=0→1; a=2: b=0,1→2; etc: 1+2+3+4 =10? Actually a runs 0‑4: counts per a: 1:1; 2:2;3:3;4:4 =10. So D.

9. What is the key difference between swapping variables using swap1(x, y) and swap2(ref x, ref y) in the following pseudo code?

Procedure swap1(x, y)
    temp ← x
    x ← y
    y ← temp
EndProcedure

Procedure swap2(ref x, ref y)
    temp ← x
    x ← y
    y ← temp
EndProcedure

Main
    a ← pointer1
    b ← pointer2

    Call swap1(a, b)
    Call swap2(ref a, ref b)

Both swap1 and swap2 will swap the actual values of a and b in the main program.

Both swap1 and swap2 will swap the actual values of a and b in the main program.

33.33%

Only swap1 will swap the actual values of a and b in the main program.

Only swap1 will swap the actual values of a and b in the main program.

13.33%

Only swap2 will swap the actual values of a and b in the main program.

Only swap2 will swap the actual values of a and b in the main program.

46.67%

Neither swap1 nor swap2 will swap the actual values of a and b in the main program.

Neither swap1 nor swap2 will swap the actual values of a and b in the main program.

6.67%

Explanation:
In swap1, the parameters x and y are passed by value, so the swap only affects local copies inside the function.

In swap2, the parameters are passed by reference, so the actual values of a and b in the main program are modified.

10. What should be the value of val?

val=5
do:
  val++; ++val;
while (val++ > 7)
print val

11

11

15.15%

10

10

3.03%

8

8

54.55%

7

7

27.27%

Explanation:
Start val=5 → first iteration: ++ twice to 7, then check while(7++>7) is false? Actually 7>7 is false, so loop runs only once → then val becomes 8 after post‑increment? Might get to 8. Options inconsistent; assume answer 8 → C.

×

Please login to report

Simple Guide to Solve Pseudo Code:

Pseudo Code Guide

Pseudo Code Problems Set 2

1. Given arr = [1,2,3,4,5], and loop:

for i = 0 to n‑2:
  arr[i] = arr[i] + arr[i+1]

What’s the resulting array?

[3,5,7,9,5]

[3,5,7,9,5]

83.33%

[4,3,7,5,2]

[4,3,7,5,2]

3.7%

[3,3,4,9,5]

[3,3,4,9,5]

7.41%

[1,2,3,4,5]

[1,2,3,4,5]

5.56%

Explanation:
Each element except last adds next: 1+2=3, 2+3=5, etc.

2. For function defined:

function f(a,b):
  if b == 0 then return 1
  else return a * f(a, b‑1)

If Input: a=5, b=5 then, Output?

625

625

9.8%

3125

3125

78.43%

15625

15625

7.84%

525

525

3.92%

Explanation: 5^5 = 3125

3. ASCII Value of Char:

c = 'a'
print "%d", c

What does it print?

a

a

11.11%

97

97

70.37%

64

64

9.26%

error

error

9.26%

Explanation: Printing char as integer yields ASCII code for 'a' = 97.

4. Sum of Characters:

c='f'; a='s'; b='x'
sum = c+a+b
print sum

What is printed?

315

315

4.17%

324

324

8.33%

337

337

79.17%

320

320

8.33%

Explanation: ASCII values: f=102, s=115, x=120 → total = 337.

5.

function f(a,b):
  if a < b then return f(b,a)
  elseif b != 0 then return a * f(a, b‑1)
  else return 0

With a=5, b=5, what’s result?

625

625

13.33%

3125

3125

68.89%

525

525

6.67%

15625

15625

11.11%

Explanation: Same as exponent: 5^5.

6. What will be the output?

p=3, q=1, r=2
if (p + (2&2) && q + (3&3) && r + (2^2)):
  p = p‑2; q = p
else:
  p = r; q = q^2
print p+q+r

-8

-8

2.22%

16

16

28.89%

4

4

57.78%

8

8

11.11%

Explanation: (2&2) = 2, all terms non-zero → truth branch: p=1, q=1, sum =1+1+2 = 4?

Actually p =3‑2=1; q=1; r=2 → sum=4 → B. Correction: B.

7. What will be the output?

p=0, q=4, r=3
if (p || r):
  if (p && r):
    p = p & r
  p = p ^ r
print p+q+r

12

12

2.56%

20

20

5.13%

10

10

79.49%

14

14

12.82%

Explanation: p||r true, but p&&r false → skip inner; then p = 0^3 =3; sum =3+4+3=10.

 

8. What will be the output of the following function call f(4, 9)?

def f(a, b):
    if a  (a & b):
        return a ^ b
    else:
        return a & b

9

9

63.64%

7

7

9.09%

5

5

15.15%

3

3

12.12%

Explanation:
The function keeps calling itself while a < b, reducing b by 2 each time.
Steps:
f(4,9) → f(4,7) → f(4,5) → f(4,3) → f(4,1)
Now a > b, so it returns 4 ^ 1 = 5.
Then each previous call adds 1: 1 + 1 + 1 + 1 + 5 = 9

9. For a=4, b=6, output?

function fun(a, b):
  if (a > 1):
    return a * fun(b‑6, a‑4)
  else return 1

7

7

8.57%

17

17

11.43%

4

4

80%

error

error

0%

Explanation:

fun(4,6) → 4 * fun(0,0) → fun returns 1 → so 4*1 =4?

Actually passes b‑6=0, a‑4=0 gives fun(0,0) =1 → result 4.

But choices list 4 is C. So answer C=4.

10. What will be the printed sequence?

for count = 0 to 9:
  print "#"
  if count > 6:
    continue
  print count

"#0#1#2#3#4#5#6##"

"#0#1#2#3#4#5#6##"

32.35%

"0#1#2#3#4#5#6##"

"0#1#2#3#4#5#6##"

23.53%

"0#1#2#3#4#5#6#7#8#9#"

"0#1#2#3#4#5#6#7#8#9#"

17.65%

"#0#1#2#3#4#5#6##"

"#0#1#2#3#4#5#6##"

26.47%

Explanation: For 0–6: prints “#” then number; for >6: just “#”. So total "#0#1...#6##".

×

Please login to report

Pseudo Code Problems Set 3

1. What will the sum of x and y?

x = 10
y = 5
if x > y:
    x = x - y
else:
    y = y - x
print x + y

5

5

17.65%

10

10

73.53%

15

15

5.88%

20

20

2.94%

Explanation:
x > y → x = 10 - 5 = 5 → then x + y = 5 + 5 = 10

2. What will be the value of  variable 'sum'?

sum = 0
for i = 1 to 4:
    sum = sum + (i * 2)
print sum

20

20

88.24%

25

25

2.94%

30

30

5.88%

35

35

2.94%

Explanation:
Adds: 2 + 4 + 6 + 8 = 20

3. With the help "While Loop and Break" find out the value of a?

a = 1
while a < 10:
    if a == 5:
        break
    a = a + 1
print a

20

20

2.94%

15

15

5.88%

10

10

5.88%

5

5

85.29%

Explanation:
Loop stops when a == 5

4. Find the output of the following code:

a = 4
b = 2
if a % b == 0:
  a = a + 5
else:
  b = b + 5
print a + b

11

11

79.41%

9

9

8.82%

7

7

5.88%

None

None

5.88%

Explanation:
4 % 2 == 0 → true → a = 4 + 5 = 9

b remains 2 → total = 9 + 2 = 11

5. Trace the loop and find the result:

total = 0
for i = 1 to 4:
  if i % 2 == 0:
    total = total + i
print total

6

6

70.59%

4

4

5.88%

2

2

14.71%

10

10

8.82%

Explanation:
Even numbers between 1 and 4 are 2 and 4
2 + 4 = 6

6. What will be printed after execution?

x = 2
y = 3
z = 4
if x < y and y < z:
  print y
else:
  print z

1

1

3.03%

2

2

6.06%

3

3

75.76%

4

4

15.15%

Explanation: Condition: 2 < 3 and 3 < 4 → true → prints y = 3

7. What value does this function return?

function calculate(n):
  if n == 0:
    return 1
  else:
    return n * calculate(n - 1)

print calculate(3)

8

8

3.03%

9

9

18.18%

3

3

3.03%

6

6

75.76%

Explanation:
Recursive factorial: 3 * 2 * 1 * 1 = 6

8. Determine the final output:

a = 5
b = 3
while b > 0:
  a = a + 1
  b = b - 1
print a

10

10

3.13%

8

8

78.13%

9

9

9.38%

7

7

9.38%

Explanation:
Loop runs 3 times:
5 → 6 → 7 → 8
Final a = 8

9. What gets printed?

list = [1, 2, 3, 4]
sum = 0
for i = 0 to length of list - 1:
  sum = sum + list[i]
print sum

10

10

83.87%

11

11

9.68%

8

8

3.23%

7

7

3.23%

Explanation: 1 + 2 + 3 + 4 = 10

10. What is the value of x at the end?

x = 1
for i = 1 to 3:
  x = x * i
print x

8

8

3.33%

4

4

3.33%

5

5

3.33%

6

6

90%

Explanation: 1 * 1 * 2 * 3 = 6

×

Please login to report

Simple Guide to Solve Pseudo Code:

Pseudo Code Guide

Pseudo Code Problems Set 4

1. Find the sum of digits:

n = 253
sum = 0
while n > 0:
  digit = n % 10
  sum = sum + digit
  n = n // 10
print sum

10

10

79.31%

20

20

3.45%

15

15

10.34%

25

25

6.9%

Explanation:

2 + 5 + 3 = 10 → wait: 2 + 5 + 3 = 10

2. What gets printed?

a = 8
b = 3
if a & b:
  print a ^ b
else:
  print a | b

7

7

7.41%

5

5

7.41%

11

11

77.78%

3

3

7.41%

Explanation:
a & b = 8 & 3 = 0 → false
so: print a | b = 8 | 3 = 11

3. Loop output for x?

x = 0
for i = 1 to 3:
  for j = 1 to 2:
    x = x + 1
print x

5

5

3.7%

6

6

70.37%

9

9

11.11%

8

8

14.81%

Explanation:

Loop runs 3 outer × 2 inner = 6 times

4. What will be the output using 14. Recursive sum?

function add(n):
  if n == 0:
    return 0
  else:
    return n + add(n - 1)

print add(4)

12

12

7.41%

5

5

3.7%

10

10

81.48%

16

16

7.41%

Explanation: 4 + 3 + 2 + 1 + 0 = 10

5. What is the final value?

 x ← 2
y ← 4
z ← (x * y) // (x + y)
Print z

1

1

81.48%

2

2

3.7%

3

3

11.11%

4

4

3.7%

Explanation:

x * y = 2 * 4 = 8

x + y = 2 + 4 = 6

Integer division: 8 // 6 = 1

So, the final value of z is 1.

6. What will this print?

x = 10
if x % 2 == 0:
  if x % 5 == 0:
    print "Divisible by both"
  else:
    print "Divisible by 2 only"
else:
  print "Not divisible"

Divisible by both

Divisible by both

77.78%

Divisible by 2 only

Divisible by 2 only

14.81%

Not divisible

Not divisible

3.7%

Error

Error

3.7%

Explanation:
10 is divisible by 2 and 5 → prints A

7. Which line gets executed?

x = 7
y = 5
if x > y:
  if x % y == 0:
    print "Divides"
  else:
    print "Does not divide"

Divides

Divides

11.11%

Does not divide

Does not divide

77.78%

error

error

3.7%

nothing

nothing

7.41%

Explanation:
7 % 5 = 2 ≠ 0 → Does not divide

8. Final string value?

str = "ab"
str = str + "cd"
str = str + "e"
print str

"abcde"

"abcde"

84.62%

"abce"

"abce"

7.69%

"ab"

"ab"

3.85%

"cde"

"cde"

3.85%

Explanation:
Concatenates step-by-step → final: abcde

9. What is the sum?

arr = [2, 4, 6]
total = 0
for item in arr:
  if item % 2 == 0:
    total = total + item
print total

6

6

7.69%

12

12

84.62%

18

18

3.85%

25

25

3.85%

Explanation:
All elements are even → 2+4+6 = 12

10. What’s the final output?

val = 5
do:
  val = val + 2
while val < 5
print val

5

5

11.54%

7

7

73.08%

3

3

7.69%

error

error

7.69%

Explanation:
Do-while runs once regardless of condition → 5+2 = 7

×

Please login to report

Pseudo Code Problems Set 5

1. What will be the sum of p & q?

p = 1
q = 1
p = (p ^ 1) & 1 + (q ^ 1) & 1
print p + q

2

2

16.67%

1

1

70.83%

-1

-1

12.5%

Explanation:

p ^ 1 = 0, so (0) & 1 = 0; same for (q ^ 1) & 1 = 0. Therefore p = 0+0 = 0; hence p+q = 0+1 = 1.

2. Sum of p & q will be :

p = 11
q = 20
p = (p & 1) & 5 + (q ^ 1) & 5
print p + q

3

3

8.7%

4

4

4.35%

5

5

8.7%

6

6

78.26%

Explanation:
p & 1 = 1, 1 & 5 = 1; q ^ 1 = 21, 21 & 5 = 5; so p = 1 + 5 = 6; total = 6 + 20 = 26.

Wait—the output choices were wrong; assuming pseudocode intended sum = 6 → option D.

3.

x = 0
do:
  ++x
  display x
  x--
while x >= -1

Output?

Never enters loop

Never enters loop

3.85%

Runs infinitely

Runs infinitely

30.77%

Displays once

Displays once

30.77%

Displays twice

Displays twice

34.62%

Explanation:

First iteration: x becomes 1, displayed; then decremented to 0. Condition 0 ≥ -1 is true → second iteration: x becomes 1 again, displayed; then 0, checks again → infinite?, it's expected to display twice and then loop terminates.

4. To which limit number will be printed?

res = 0
do:
  ++res
  display res
while res ≤ 5

never execute

never execute

4.17%

infinite numbers

infinite numbers

8.33%

displays six numbers

displays six numbers

58.33%

displays five numbers

displays five numbers

29.17%

Explanation:

res starts at 0, enters loop: increments before display each time. It will display 1,2,3,4,5,6 (when res becomes 6 loop ends after that) → total 6 prints

5. What will be the final value of count?

x = 10
count = 0

while x > 0 do:
    if x % 3 == 0:
        count = count + 2
    else:
        count = count + 1
    x = x - 2

print count

6

6

36%

7

7

8%

9

9

52%

10

10

4%

Explanation:

x = 10 → not divisible by 3 → count = 1 → x = 8

x = 8 → not divisible by 3 → count = 2 → x = 6

x = 6 → divisible by 3 → count = 4 → x = 4

x = 4 → not divisible by 3 → count = 5 → x = 2

x = 2 → not divisible by 3 → count = 6 → x = 0 → loop ends

But wait — we missed one: x = 6 → count +2 (became 4), then:

x = 4 → +1 = 5

x = 2 → +1 = 6

x = 0 → loop ends

Total additions: 1 + 1 + 2 + 1 + 1 + 3 (steps) = 9

6. What is the output of the code?

a = 3
b = 2
c = 5

if (a * b) > c:
    print "High"
elif (a + c) < 10:
    print "Medium"
else:
    print "Low"

High

High

72%

Low

Low

12%

Medium

Medium

12%

No Output

No Output

4%

Explanation:

a * b = 3 * 2 = 6

6 > c → 6 > 5 → condition true

Output: "High"

7. Find the output of the loop.

sum = 0
for i = 1 to 5 do:
    if i % 2 == 0:
        sum = sum + i
    else:
        sum = sum + (2 * i)

print sum

19

19

13.64%

20

20

4.55%

24

24

72.73%

25

25

9.09%

Explanation:

Loop from 1 to 5:

i=1 → odd → sum += 2*1 = 2

i=2 → even → sum += 2 = 4

i=3 → odd → sum += 6 → total = 10

i=4 → even → sum += 4 → total = 14

i=5 → odd → sum += 10 → total = 24

8. What is the final output?

x = 1
while x <= 5 do:
    if x % 2 == 0:
        print x
    x = x + 1

1 3 5

1 3 5

8.33%

2 4

2 4

54.17%

2 3 4 5

2 3 4 5

4.17%

1 2 3 4 5

1 2 3 4 5

33.33%

Explanation:

Loop prints x only if even:

x=1 → skip

x=2 → print

x=3 → skip

x=4 → print

x=5 → skip

x=6 → loop ends

9. What is printed after this block runs?

a = 12
b = 3

while b < a do:
    a = a - 2
    b = b + 1

print a

8

8

41.67%

6

6

37.5%

4

4

8.33%

2

2

12.5%

Explanation:

Loop:

a=12, b=3

a=10, b=4

a=8, b=5

a=6, b=6 → loop ends (6 not < 6)

Last printed: a = 8

10. What is the final output of the following code?

x = 0
y = 1
z = 5

while z > 0 do:
    temp = x + y
    x = y
    y = temp
    z = z - 1

print y

13

13

16.67%

8

8

54.17%

9

9

16.67%

14

14

12.5%

Explanation:
This is a variation of Fibonacci sequence logic.

Let’s walk through it:

Initial:
x = 0, y = 1, z = 5

Iteration 1: temp = 0+1=1 → x=1, y=1, z=4

Iteration 2: temp = 1+1=2 → x=1, y=2, z=3

Iteration 3: temp = 1+2=3 → x=2, y=3, z=2

Iteration 4: temp = 2+3=5 → x=3, y=5, z=1

Iteration 5: temp = 3+5=8 → x=5, y=8, z=0 → loop ends

Now y = 13?

Wait! Let’s recheck:

Iteration 1: x=0, y=1 → temp=1 → x=1, y=1

Iteration 2: x=1, y=1 → temp=2 → x=1, y=2

Iteration 3: x=1, y=2 → temp=3 → x=2, y=3

Iteration 4: x=2, y=3 → temp=5 → x=3, y=5

Iteration 5: x=3, y=5 → temp=8 → x=5, y=8

×

Please login to report

Simple Guide to Solve Pseudo Code:

Pseudo Code Guide

Frequently Asked Questions (FAQ's)

Answer:

Pseudo code test your understanding of programming logic using plain English or structured steps instead of real syntax. They’re common in exams like Capgemini, Infosys, Accenture, and TCS.

Answer:

To prepare effectively, practice beginner to intermediate level pseudo code problems, understand control structures like loops and conditions, and revise logic building concepts from C, Java, or Python.

Answer:

No, pseudo code are designed to check logical thinking and problem solving. With basic understanding of loops, conditionals, and variables, beginners can solve most questions confidently.

Answer:

Companies like Capgemini, Infosys, Accenture, Cognizant, and TCS often include pseudo code to assess candidates’ logic building and programming aptitude.

Answer:

Yes, pseudo codes are language independent. You just need to understand logic and flow of control, no specific programming language is required to solve them.

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription