Infosys Pseudocode Questions

Question 1

Given the pseudocode for performing Binary search in an array of elements sorted in ascending order. What operation must be implemented in the 3rd so that the execution of binary search is successful?

  1. Middle element should be compared with x.
  2. If x and the middle element match, we return the middle index.
  3. _ _ _ _ _ _ _ _ _ _ _
  4. Else ( x is smaller than the middle element) recur for the left half
Tick

Else if x is greater than the middle element, then x can only lie in the right half subarray after the middle element. So we recursively search for the right

Cross

Else if x is greater than the middle element, then x can only lie in the left half subarray after the middle element. So we recursively search for left

Cross

None of the above

Cross

Else if x is less than the middle element, then x can only lie in the right half subarray after the middle element. So we recursively search for the right



Question 2

Predict the output of the given pseudo code if the value of the number is 6: 

Read number 
k = 2 
i = 2 
while i <= number:
    k = k * i 
    i = i +1 
end while 
write k

Tick

1440.0 

Cross

1340.0

Cross

1700.0

Cross

1560.0



Question 3

What will happen for the below pseudocode:

Set Integer res = 0 
do 
    --res 
    display res 
    res++ 
While(res >= 0) 
End do-while

Cross

The program will not enter the loop.

Tick

Code will run infinite number of times.

Cross

Code will execute and the value of res will be displayed once.

Cross

Code will execute and the value of res will be displayed twice.



Question 4

What is the output of the below pseudocode?

Set value = ' ' * 10;
print value

Cross

100

Tick

320

Cross

10

Cross

200



Question 4-Explanation: 

As the ASCII code for a blank space is the decimal number 32, thus 32 * 10 = 320

Question 5

What happens when the below pseudocode is executed?

Set Integer value = 10 
Set Integer salary= 0 
While (value = 10) 
    salary = salary + 100 
    display salary
END While

Cross

Code executes successfully and the value of salary is displayed once.

Cross

Code executes successfully and nothing is displayed.

Tick

Code executes successfully the value of salary is displayed infinite times.

Cross

Compilation error.



Question 5-Explanation: 

As the value of the variable "value" is not changing throughout the while loop so while loop will not hit false condition also it will never break

Hence Option (C) is correct.

Question 6

Count the number of " * " printed by the given pseudo code when the input is 25. 

Write "Please enter a number" 
Read input 
Repeat while input > 0 
    if( input > 0 and input <=12 ) 
        Write * 
    else if ( input >12 and input <=24 ) 
        Write ** 
    else if ( input >24 and input< = 30 ) 
        Write *** 
        input -- 
    end if 
End while

Tick

39.0

Cross

57.0

Cross

35.0

Cross

29.0



Question 7

Count the number of " # " printed.

For m = 0 to 14 do
    For n = 0 to 14 do
        display '#'
    End-for
    if(m = 5) then do
        break
    End-if
End-for

Cross

13

Tick

84

Cross

28

Cross

63



Question 8

Count the number of " # " printed.

For x = 0 to 8 do
    For y = 0 to 6 do
        display '#'
    End-for
    If(x = 2) then do
        break 
    End-if 
End-for

Cross

14

Cross

13

Tick

21

Cross

20



Question 9

What will be the output of the following pseudocode?

Integer x, y, z 
Set x = 4, y = 3, z = 1 
if (x >> (z - 1) && y << (z + 1)) 
    x = x + c 
else 
    y = x << z 
End if 
Print x - y + z

Cross

5

Tick

3

Cross

8

Cross

None of these

Cross

2



Question 10

What will be the output of the given pseudo code if n = 10?

Read n
Initialize i to 5, sum to 0
while i < n do
    increase sum by i
    increment i
end while
Write sum

Tick

35.0

Cross

25.0

Cross

45.0

Cross

55.0



There are 20 questions to complete.


  • Last Updated : 27 Sep, 2023

Share your thoughts in the comments
Similar Reads