NEWPSEUDO
NEWPSEUDO
Set value = 1, n = 45
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.
Answer is option C
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.
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.
Answer is option D.
Set m = 1, j = 1
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
= 1 + 0
= 1
= 0 + 1
= 1
Now m = m + a[j]
= 1 + 5
= 6
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
C. 150
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
for(each k from 0 to 4)
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,
3, 5, 1, -5, -9
for(a = 0 to 4)
for(b = 0 to 2)
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.
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.
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
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
Now, r = q / 5
= 6 / 5
= 1
So q = 6 and r = 1
Answer is option D
Print “9”
otherwise
Print x MOD 9
end if
A. 8
B. 16
C. 7
D. None
Answer - Option C
Explanation:
Here x = 259
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
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
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)
End if
a = a + a + a + a
return a
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
a = a+b+b-2
return 3-a
Else
End if
return a-b+1
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
a=a^b
Else
End if
return a-b
return a+b
A.-9
B.5
C.6
D.21
Answer - Option B
Explanation:
Here the if condition will result in true statement as given below
Then a = a ^ b
Answer is option B
if(a > b)
End if
if(b > a)
End if
b = b ^ a
a = a ^ b
return a + b
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
= 0 1 0 0
1 1 0 0
--------------
1 0 0 0 à 8
Answer is option B
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
Initialize Integer x, y, z
Set y = 1, x = 2
z = x ^ y
Print z
1
Wrong
2
Right
3
Explanation :
Firstly variables x, y, and z are initialized, then y and x are assigned values 1
and 2 respectively.
Now z is assigned the value of x XOR y i.e. 1 ^ 2 = 3. Since all bits in 1 and 2
are exclusive so the XOR will be equal to 1 OR 2 i.e. 3
Integer a, b, c
Set b = 4, c = 5
for(each a from 2 to 4)
print c
b = b - 1
c = c + b
end for
Right
5 8 10
Wrong
1 3 6
8 9 10
3 6 9
Explanation :
Firstly variables a, b, and c are initialized, then b and c are assigned values 4
and 5 respectively.
Now run a loop from 2 to 4, in each iteration b is decremented by 1, and c is
incremented by b.
In the first iteration print c = 5 value of b is decremented by 1 i.e. b = 3, c is
incremented by b i.e. c = 5
In the second iteration print c = 8 value of b is decremented by 1 i.e. b = 2, c is
incremented by b i.e. c = 8
In the third iteration print c = 10 value of b is decremented by 1 i.e. b = 1, c is
incremented by b i.e. c = 10
Integer x, y
Set x = 15, y = 12
y = x – 1
do{
Print x
x = y + (x – 2)
}
while(x < 40)
end do while
Wrong
14 26
Right
15 27 39
27 39
15
Discuss it
Question 4 ‒ Explanation
Firstly variables x and y are initialized, then x and y are assigned values 15 and
12 respectively.
Then Assign y the value of x - 1.
print x i.e 15
do while loop runs till x is less than 40 assign x with the value of y + x - 2 and
print x
The order in which value of x changes is 15 then 27(14 + 15 - 2) then 39(14 + 27 -
2), then 51(14 + 39 - 2) and the do while loop terminates.
Initialize Integer x, y, z
Set y = 1, x = 2
z = x & y
Print z
Right
0
Wrong
3
***********************************************************************************
************************************************************
Integer j, m
Set m=0
Integer a[4] = {10, 11, 3, 2}
For(each j from m to m+3)
If( j > 0)
a[j] = a[j-1] + 2
End If
End For
m = a[0] + a[2] + a[1]
Print m
Initialization:
m = 0
a = {10, 11, 3, 2}
Loop Execution:
When j = 0:
The condition j > 0 is false, so nothing changes.
When j = 1:
The condition j > 0 is true.
a[1] = a[0] + 2 = 10 + 2 = 12
Now, a = {10, 12, 3, 2}
When j = 2:
The condition j > 0 is true.
a[2] = a[1] + 2 = 12 + 2 = 14
Now, a = {10, 12, 14, 2}
When j = 3:
The condition j > 0 is true.
a[3] = a[2] + 2 = 14 + 2 = 16
Now, a = {10, 12, 14, 16}
After the Loop: