Q1) 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 - Option C
Explanation:
There are three variables which are declared from which num is not initialized. So the default value of integer is assigned to num and that is 0.
num>>1 will result in 0 only.
num = num + value means 0+1 i.e., 1 will be assigned to num
So, when we print num value it will be 1.
Answer is option C
Q2) 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 - Option D
Explanation:
Here x is starting with 1 inside the for loop. The value of x is varying from 1 to 11.
If we write the for loop it will be as follows.
for(x=1;x<=11;x++)
{
x=x+2
}
Consider the first iteration, x =1 then x<=11 condition is true, it will enter inside the loop, then x will become x+2 that is 1 + 2 = 3. Then again it will go to the update the x will become 4. In short after each iteration x value is incremented by 3. Next it will become 4 + 3 =7. Like that it goes on.
It will repeat until the condition becomes false.
When the condition become false x value will be 13.
Answer is option D.
Q3) 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]
Print m
A.3
B.2
C.6
D.4
Answer - Option C
Explanation:
Here m =1, j=1
a[3] = {0,1,0}
a[0] = a[0] + a[1]
= 0 + 1
= 1
a[1] = a[1] + a[2]
= 1 + 0
= 1
a[2] = a[2] + a[0]
= 0 + 1
= 1
If(a[0]) results in true, so
a[j] => a[1] which is assigned as 5
Now m = m + a[j]
= 1 + 5
= 6
So the answer is option C.
Q4) 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 - Option B
Explanation:
Initially the value of k is 150. Here if condition will not be true until the value of k is not greater than 155.
So, each time before it reaches the recursive function the print statement above that function call will be working and it will print 150 152 154. After that the k value will become 156 for which the if condition will be true. Then onwards the recursive will start returning.
During the function call each value will be on the top of the stack so latest k value, that is 154 is printed based on the print statement given below the function call. So then it will start printing 154 152 150
Finally, the answer is option B.
Q5) 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 - Option B
Explanation:
Here in first for loop we are storing the values in c array as,
c[k] = a[k] – b[k]
So in array c elements are
3, 5, 1, -5, -9
In the next for loop we are printing c array
So, answer is option B
Q6) 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 for
End for
End if
A.8
B.7
C.9
D.10
Answer - Option C
Explanation:
Here outer loop will work 0 to 4 means totally 5 times and inner loop will work 0 to 2 means three times for every outer loop.
Initially a and b both are 0. The if condition will fail.
Next iteration a =1, then inner loop b, will start again with 0
So the values for which the conditions are a true are as follows.
a = 1, b=0 -à 1 will be printed once
a = 2, b= 0,1 -à 2 will be printed twice
a = 3, b= 0,1,2 -à 3 will be printed thrice
a = 4, b = 0,1,2 -à 4 will be printed thrice
So totally a will be printed 9 times
Thereby answer is option c
Q7) 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 - Option D
Explanation:
Here initially q =13
When for loops starts, p =1
Then, r = q % p
= 13 % 1
= 0
p will be p + 5
p = 1 + 5
= 6
Then q is overwritten as
q = p + r
= 6 + 0
= 6
Then the loop will end because p is already 6 now
Now, r = q / 5
= 6 / 5
= 1
So q = 6 and r = 1
Answer is option D
Q8) 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 - Option C
Explanation:
Here x = 259
If (x==0) is false, so it will not print 0
Then If(x%9 ==0) is also false, so it will not print 9
Now it will print x%9, that is 259%9 the remainder is 7
So, answer is option C
Q9) 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 - Option A
Explanation:
a = 12, b= 25
a = (a+b) % 2
= (12+25) % 2
= 1
b = b = a à b = 1
a = a+b-13
= 1+1-13
= -11
So, answer is option A
Q10) 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 - Option D
Explanation:
Here initially a=b=c=4
All values are same.
Coming to the if condition the operators used are bitwise operators.
So we need to convert all values to its corresponding binary.
Inside the If the condition given inside bracket will be executed first which is an xor operator. If the bits are same xor will result in 0. Here b ^ b will result in 0.
Remaining are bitwise AND operator. If any single value is 0, while performing AND operator, result will be 0 only
Finally If(0) means false only. So it will not enter inside if block
So a+b+c means 4+4+4 = 12
Answer is option D
Q11) 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
End function funn()
A.40
B.30
C.44
D.0
Answer - Option A
Explanation:
Here, if (0) results in false so it will not go to the if block
Then a = a + a + a + a
= 10 + 10 + 10 + 10
= 40
So, the answer is option A
Q12) 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
End if
return a-b+1
return a+b End function fun()
A.0
B.5
C.16
D.11
Answer - Option B
Explanation:
Here the if condition can be expanded as follows
If( ( 1 + 5 || 5 – 1) && (1>5) && 1) this will result in false because 1>5 is false so entire condition will result in false. Then it will go to the else part where it is returning a - b + 1
That means, 5 - 1 + 1 which is 5
So, the answer is option B
Q13) 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
End if
return a-b
return a+b
End function funn()
A.-9
B.5
C.6
D.21
Answer - Option B
Explanation:
Here the if condition will result in true statement as given below
If( ( b % a && a % b) || (a ^ b > a) ) means
If( ( 1 % 5 && 5 % 1) || (5 ^ 1 > 5) ) the condition before Logical OR is false and condition after it is true.
In 5 ^ 1 > 5 condition relational operator have higher precedence than bitwise operator so 1 > 5 is false so it 5 ^ 0 which will result in 5. Finally false or true will result in true statement so it will enter the if block.
Then a = a ^ b
= 5 ^ 1 which will result in 4. So latest value of a is 4.
Return a – b is inside the else part.
Next line of statement will be executed, that is return a + b which is 4 + 1 = 5
Answer is option B
Q14) What will be the output of the following pseudocode for a = 4, b = 8?
Integer funn(Integer a, Integer b)
if(a > b)
End if
if(b > a)
End if
b = b ^ a
a = a ^ b
return a + b
End function funn()
A. 35
B. 20
C. 14
D. 25
Answer - Option B
Explanation:
Here a= 4 and b= 8
If(a>b) will result in false condition, next if(b>a) will result in true.
After that next set of statements will be executed. Here we are using bitwise operators so we need to convert a and b to binary representation.
a = 4 à 0 1 0 0
b = 8 à 1 0 0 0
now b = b^a
= 1 0 0 0
0 1 0 0
-----------
1 1 0 0 à 12
Same way a = a^b
= 0 1 0 0
1 1 0 0
--------------
1 0 0 0 à 8
Now we need to return a + b that means 12 + 8 = 20
Answer is option B
Q15) 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 - Option B
Explanation:
Here there is nested if condition given
If (x==1) will result in false statement so it will go to the else of outer if condition where it will print C.
So answer is option B