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

NEWPSEUDO

Uploaded by

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

NEWPSEUDO

Uploaded by

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

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

What will be the output of the following pseudocode?

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

Which of the following series will be printed by the given pseudocode?

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

Thus the final series is 5, 8, 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.

The final series obtained is 15 27 39

What will be the output of the following pseudocode?

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:

The loop runs from j = m to j = m + 3, which is from j = 0 to j = 3.


Iteration Details:

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:

a = {10, 12, 14, 16}


Calculation of m:

m = a[0] + a[2] + a[1]


m = 10 + 14 + 12
m = 36
Print m:

The output will be 36.


So, the output of the pseudocode is 36.

You might also like