Cocubes Pseudocode
Cocubes Pseudocode
Test Summary
No. of Sections: 1
No. of Questions: 250
Total Duration: 60 min
Section 1 - MCQ
Section Summary
No. of Questions: 250
Duration: 60 min
Additional Instructions:
None
12:20:03
4:50:00
12:30:30
Start
Declare Integer x
Set x=1
While (x<20)
print x
x=x*5
End while
It prints all multiples of 5 between 1 and 100 (excluding both 1 and 100)
non of these
integer a,b
set b=625;
for a=1 to 4
b=b/5;
a=a+b;
end for
print a
127
29
152
87
12
Q6. Integer a, b, c
set a=6, b=8, c=15
if ((b^a)<a)
b=a
End if
printf a+b+c
[Note: The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
29
35
38
48
Q7. What will be the output of the pseudocode for p=3, q=1?
Integer funn( integer p, integer q)
if(q&1>0 AND p&3>0)
return p^q
else
return funn (p,q)
end if
end function funn( )
[Note- &:bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit of the second
operand. The corresponding result bit is set to 1. Otherwise , the corresponding result bit is set to 0.
^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its second operand. If
one is 1 , the corresponding result bit is set to 1. Otherwise, the corresponding result it is set to 0].
-12
20
123
122
127
Integer j, m
set m = 14
integer a [ 4 ] = { 1, 13, 1, 1 }
for ( each j from 0 to 3 )
if ( a [ j ] > 1 )
continue
else
m=a[j]
end if
m=m^6
end for
print m
10
134
136
130
132
12
17
-10
Integer p, q, r
set p=1, q=1, r=1
if (0 | | 1 | | 1 )
p= p & 1
else
r=r&1
end if
print p + q + r
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit of the second
operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
| |: Logical OR - The logical OR operator (| | ) returns the boolean value True (or 1) if either or both operands is True and returns
False( or 0), Otherwise
If (X) gets executed if the value inside if( ), ie, x is not zero]
18
-1
10
24
16
12
15
13
15
-1
21
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit of the second
operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0 ]
31
40
35
50
Q18. What will be the output of the following pseudocode?
Integer p, q, r
set p= 1, q= 1, r= 2
q=p-1
q=r-1
if (p + 2 > q -6)
if (q+2 > p- 6)
p=2
end if
q= 2
if (r> 5)
p=q
end if
end if
printf p + q + r
10
17
24
15
19
20
[Note - >> - Bitwise right shift operator, it takes two numbers, right-shift the bits of the first operand the second operand decides the
number of places to shift
&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
18
2
10
48
30
38
32
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
32
14
15
Integer p, q, r
set p= 8, q= 8, r= 9
if ((r&p) + (p+q) > (r+q))
p=q
r = ( p+ 11) + q
end if
if (( p + r ) < ( q - p ))
q=r+p
p=5
end if
print p + q + r
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
43
44
39
54
Integer a, b, c
set a= 7, b= 7, c= 7
if ((7- b - c) > ( c + a ))
if (( 5 - 7 ) < ( 7 + a ))
c= ( 3 & 11 ) & c
a=a
end if
c=7+c
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
27
21
31
-3
Integer a, b, c
set a= 0, b= 2, c= 13
if (( c-7) < ( 7+c))
if (( b^c) < a)
a= b
a=a+a
end if
end if
print a = b + c
[Note: The bitwise Exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
18
14
27
15
Integer a, b, c
set a= 5, b = 4, c= 7
for (each c from 5 to 8)
a= 7
end for
for ( each c from 5 to 6 )
a = b ^a
a= 1 + c
end for
print a + b
[Note: The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
17
22
-9
13
Integer a, b, c
set a= 1, b= 5
for (each c from 6 to 7)
a=a&c
a=a+c
end for
print a + b
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
19
18
36
14
Q29. What will be the output of the following pseudocode?
Integer p, q, r
set p= 1, q= 4, r= 2
if ( p&q)
r =p&q
end if
print r- p - q
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
11
-9
-3
Integer j, m
set m = 1
integer a[4] = { 0, 1, 0, 2}
a[0] = a[ 2]
a[1] = a[0]
a[2] = a[1]
a[3] = a[2]
m= a[3]
if (m > 0)
m = m -1
end if
print m
-4
0
8
Integer j, m
set m= 1
integer a[7] = { 1, 2, 3, 0, 5, 4, 7}
for ( each j from 2 to 5 )
if ( a[j + 1] > a[j] && a[j - 1] > a[j] )
m= m + a[j]
end if
end for
print m
[Note: && : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
17
-2
18
31
28
21
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^ is the bitwise exclusive OR operator(^) that compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
4
21
-1
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
>> - Bitwise right shift operator, it takes two numbers, right-shift the bits of the first operand the second operand decides the
number of places to shift
&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
^- The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
13
19
11
Q37. What will be the output of the following pseudocode for p =1, q= 1 ?
Integer funn ( integer p, integer q )
if ( q < 1 )
return p
else
return p + funn( p, p - 1)
end if
return q
end function funn( )
-13
20
Integer a, b, c
set a= 2, b= 7, c= 11
b= (a & a ) + a
b=2^a
if (( c + b) < (b - c))
c= (11 + 4) ^ b
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^ - The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
25
16
13
Q39. What will be the output of the following pseudocode for p= 1, q=2 ?
Integer funn( integer p, integer q)
if( q^ 2 > q^ 3)
p= q^ 2
else
q= p & 2
end if
return p ^ q
end function funn ( )
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^- is the bitwise exclusive OR operator(^) that compares each bit of its first operands to the corresponding bit of its second
operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
11
2
1
Integer a, b, c
set a= 8, b= 7, c=10
If ((a -b) > ( b- a))
c= 7 + b
if (( b+c) < ( a-b) )
b= 3 + a
end if
c= (4 ^ 11) & b
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^- is the bitwise exclusive OR operator(^) that compares each bit of its first operands to the corresponding bit of its second
operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
32
22
18
25
Integer a, b, c
set a= 8, b= 4, c= 15
if(( 9 + c ) & (5 ^ a) > ( b ^ a ))
b= a
a= (a + 2) + b
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^- is the bitwise exclusive OR operator(^) that compares each bit of its first operands to the corresponding bit of its second
operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
27
37
22
32
Integer a, b, c
set a= 7, b= 2, c= 8
b = ( b&b) + b
a= (5 & 11) + a
c= c
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0]
30
20
15
22
Integer a, b, c
set a= 1, b = 2 , c= 1
a= c
c= a
b= a
print a + b + c
13
15
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
-3
Integer a, b, c
set a= 2, b= 4, c= 8
a=b
if (( c & a) < b OR c < a)
c= (c ^ 6) + a
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0
^ - is the bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
26
23
29
31
Integer j, m
set m= 3
Integer a[4] = { 11, 11, 111, 11}
for (each j from 1 to 2)
if ( a[j - 1] + a[j] + a[j+1] )
m=m+1
end if
end for
print m
13
-2
[Note: ^ The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second
operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
-3
Integer p, q, r
set p= 8, q= 6, r= 4
for ( each r from 4 to 6)
q= ( q+ 10) + q
if (( p & 4 ) < q)
q= 8 + p
else
r= 9
r= p + p
end if
end for
print p + q
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0]
24
26
36
22
Integer m
set m=4
integer a[4] = { 1, 5, 6, 8}
a[3] =1+ a[2]
if ( m > a[3])
m= m-1
end if
print m
-8
22
Integer a, b, c
set a=5, b= 11, c= 7
for ( each c from 2 to 3)
b=9+a
end for
print a + b
24
20
15
19
18
31
28
21
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^- The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
11
Q53. What will be the output of the following pseudocode for p= 5, q=2 ?
Integer funn(integer p, integr q)
if( q& p < p^q)
p = p^3
else
q = p^2
else if
return p + q
end function funn ( )
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0
^ - is the bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
10
16
8
Q54. What will be the output of the following pseudocode?
Integer j, m
set m = 1
integer a[4] = {4, 3, 2, 1}
a[0] = a[0] + a[1]
a[3] = a [3] + a[0]
m= a[3] + a[0]
print m
12
15
20
18
Integer j, m
set m= 1
integer a[4] = { 1, 1, 1, 2}
a[2]= a[1] - a[2] + a[3]
a[3] = a[2]
m= a[3]
print m
-6
16
Integer p, q, r
set p= 2,q= 0, r= 0
if (p)
r= 1
end if
if (q)
q=1
end if
print p + q + r
[Note: If (X) gets executed if the value inside if( ), ie, x is not zero]
21
3
Q57. What will be the output of the following pseudocode?
Integer a, b, c
set a= 2, b= 2
for (each c from 1 to 3)
a= (a & c) - c
end for
print a + b
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
-6
10
-1
Q58. What will be the output of the following pseudocode for a=1, b=2 ?
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
-1
21
Integer a, b, c
set a=6, b= 2, c= 7
c= 11
for (each c from 4 to 5)
a= (b^c) +c
a= (8+6) + a
a=c
end for
a= (b+b) + a
print a + b
[Note: ^ is the bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second
operator. The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
12
11
10
17
Integer a,b,c
set a=9, b = 11, c=9
if ((a+ b) < ( b-a))
c=12 + b
if (( a & 5) < c)
c=12
a=(12+7) + c
end if
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0]
44
34
54
55
Q63. What will be the output of the following pseudocode for p=2, q=3?
10
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0
^ - The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
12
16
23
20
Integer a, b, c
set a=5, b= 4, c =7
for (each c from 5 to 8)
a=3
end for
for (each c from 5 to 6)
a=b^a
a=1+c
end for
print a + b
[Note: ^ - is the bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second
operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
-11
-9
11
10
Q66. What will be the output of the following pseudocode for a= 5 , b=3 ?
11
12
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0
^ - is the bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
Integer a, b, c
set a=12, b=13
for (each c from 5 to 7)
if ( a> c)
b=10
else
Jump out of the loop
end if
a=b
end for
print a + b
22
20
30
Integer j, m
set m =1
integer a[4] ={ 1, 0, 0, 0}
if (a [0] + a[3] > 0)
for (each j from 1 to 2)
if ( 1> 2)
continue
else
if (a[j] > 2)
m= 2
end if
end if
end for
end if
print m
Note: continue when a continue statement is en-counted inside a loop, control jumps to the beginning of the loop for next iteration,
skipping the execution of the statement inside the body of the loop for the current iteration
-3
15
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
^ - The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
35
44
12
30
Integer j, m
set m = 1
integer a[4]= { 1,11, 21, 12}
for (each j from 0 to 3)
if (j -1 > a[j] + 3)
jump out of the loop
end if
m = a[j]
end for
print m
10
12
16
18
integer a, b, c
set a=1, b= 3, c= 2
if (( a&b) && (b&c) && (c&a))
a = a&b
else
b= b& a
end if
print a + b + c
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0
&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
15
666
656
555
654
12
11
10
[Note: A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the
block, or not given Boolean condition at the end of the block]
integer j,m
set m=1
integer a[4]={0,1,0,2}
a[1] = a[0] + a[3]
a[2] = a[1] + a[2]
a[3]= a[2]
m = a[3]
if (m)
m= m -1
else
m= m+1
end if
print m
[Note: if (x) gets executed if the value inside if(), i.e,, not zero]
Q77. What will be the output of the following pseudocode for p=22, q=4, r=2?
Integer fun(integer p, integer q, integer r)
if(p>1)
fun(p-r, q+2, r+2)
print q
end if
end function fun()
20 14 8 0
14 12 10 8 6 4
20 18 16 14 12
Q78. What will be the output of the following pseudocode for a= 125?
integer fun1(integer a)
if(a < 4)
return a- 5
else
return fun1((a/5)-2)
end if
end function fun1()
-3
1
-5
-12
-4
15 60 50 40 30 9 4 -1
14 60 50 40 9 4 -1
14 50 40 30 9 4 -1
Q81. What will be the output of the following pseudocode for x=75?
integer fun(integer x)
if((x - 35)>(x /4))
return (x/2)+5
else
return fun(fun( x/2))
end if
end function fun ( )
44
42
22
28
integer a,b,c,a1,b1,c1,a2,b2,c2
set a1=2, b1=45, and c1=36
set a2=11, b2=26, and c2=30
c=c1 + c2
b=c/60
c= c mod 60
b= b+ b1 + b2
a= b/60
b= b mod 60
a= a + a1 +a2
print a:b:c
14:12:6
13:71:66
13:12:66
14:12:1
Q83. What will be the output of the following pseudocode for a=5, b=4?
integer funn(integer a, integer b)
if(b>a || a>0)
b=a
a=0
end if
if(b< a || a>0)
b= a-b
end if
return a+b
end function funn( )
[Note- ||: Logical OR operator(||) return the boolean value TRUE(or 1) if either or both operands FALSE(or 0)
17
[Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operands to the corresponding bit of its second
operand.If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set 0.
if (x) gets executed if the value inside if(), i.e,, not zero]
6
16
[Note &&: Logical AND operator (&&) returns the boolean value true (or 1) either false (or 0)
if (x) gets executed if the value inside if(), i.e,, not zero]
13
23
14
11
Q86. Consider the following pseudocode mentioned below. For how many times the loop will be taken:
integer a
set a=1
while(a<5)
a=a+2
end while
print a
integer m,n
set m=9, n=6
m= m+1
n=n-1
m=m+n
if(m>n)
print m
else
print n
end if
6
15
10
Q88. For which of the following inputs, the following pseudocode will execute both the print statements?
integer a, b, c
if( a > b OR a > c)
print a
if( a+ b > c AND b< c)
print b
integer a, b,c
set a=2, b=2
if(a>2)
for (each c from 1 to 2)
a= a-b
if(0)
a= a+1
end if
a= a+b
end for
else
a= a-2
print a+b
[Note: if (x) gets executed if the value inside if(), i.e,, not zero]
11
13
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
1234
0123
0120
343 344
343 342
340 342
300 342
[Note; << is left shift operator, it takes two numbers, left shift the bits of the first operand, the second operand decides the number
of plan
>>- Bitwise right shift operator, it takes two numbers, right-shift the bits of the first operand decides the number of mod finds the
remainder after the division of one number by another, For example, the expression " 5 mod 2" would evaluate to 1 because the
leaves a quotient of 2 and a remainder of 1.
||: Logical OR -the logical OR operator(||) returns the boolean value true(or 1) if either or both operands is true and returns false(or 0)
]
10
9
11
Q93. Consider the pseudocode mentioned below, what do the functions fun( ) do in general?
calculates yx
calculates x*y
calculates xy
calculates x+x*y
[Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operands to the corresponding bit of its second
operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set 0.]
11
17
Q95. What will be the output of the following pseudocode for a=4, b=9?
integer funn(integer a, integer b)
if(b>a)
a= a+b
a= a+b
b= b+a
if(a>b)
a=a-b
return a
else
b=b-a
a=a^b
b=b^a
end if
a=1
end if
return a+b
end function funn()
[Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operands to the corresponding bit of its second
operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set 0.]
31
23
22
25
Q96. What will be the output of the following pseudocode for a=8, b=8?
[Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operands to the corresponding bit of its
second operand.If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise the
corresponding result bit is set 0.]
40
48
39
46
integer p,q,r
set p=1,q=1,r=3
p= p+((p ^ r)&q)
q=q+((p & r)^ q)
q=r+((p & r)^q)
print p+ q +r
[Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operands to the corresponding bit of its
second operand.If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise the
corresponding result bit is set 0.]
15
Q98. What will be the output of the following pseudocode for a=4, b=6?
integer funn (integer a, integer b)
if(a>2)
if(b>2)
return a+b +funn(a + 1,b - 5)
end if
end if
return a-b
end function funn( )
12
14
17
22
[||: Logical OR -the logical OR operator(||) returns the boolean value true(or 1) if either or both operands is true and
returns false(or 0) ]
1.000000
0.000000
2.000000
Q100. What will be the output of the following pseudocode p=20, q=25, r=30?
integer fun(integer p, integer q, integer r)
if(p>1)
fun(p-r, q,r-3)
print q
end if
end function fun
25
20
15
integer p,q,r
set p=15,q=3
r=p/q
q= p mod r
p=(p+ q+ r)/5
print p, q, and r
15 3 5
405
455
15 3 3
Q103. What will be the output of the following pseudocode for a=7, b=4?
integer funn(integer a, integer b)
if (a>1 && b>1)
return a+ funn(b - a, a-b)+b
end if
if(a)
return b
end if
return 10
end function funn()
27
12
14
19
Q104. What will be the output of the following pseudocode for n=35?
integer fun1(integer n)
if (n>5)
fun1(n-5)
print n
fun1(n/5)
end if
end function fun1()
10 15 20 25 30 6 35 7
20 25 30
10 15 20 25 30
35 7
13
22
18
Q106. What will be the output of the following pseudocode for a=4, b=2?
integer funn(integer a, integer b)
if (b>a && a>0)
return funn(b - 2, a - 2)
else
return b - a
end if
return 1
end function funn ()
-4
-2
Q107. consider the pseudocode mention below.For how many times the while loop will occur?
integer a
set a=1
while(a<5)
a= a+2
end while
print a
2
5
Q108. What will be the output of the following pseudocode for p=3, q=7?
integer function funn(integer p, integer q)
integer r
set r=p
p=q
r=p
q=r
p=r
return p+q
end function funn ()
14
23
15
Q109. What will be the output of the following pseudocode for x=45?
integer fun(integer x)
if((x MOD 6) MOD 2> 0)
return x/9
else
return fun(x/9)
end if
end function fun()
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
infinite loop
Q110. What will be the output of the following pseudocode for i=12?
integer fun (integer i)
if ((i/2)<(i MOD 2))
return i+1
else
return fun(fun( i -6))
end if
end function fun ()
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
12
-7
13
-6
Q111. What will be the output of the following pseudocode for a=9, b = 7?
17
-5
char str[20]
integer s
set str ="ABCDEFGH"
s=string_length(str)
str[5]=NULL
s=strlen(str)
print s
10 24
5 10
10 36
15 20
11
-1
15
integer k, m
set m=0
integer p[3]={1,7,6}
for (each k from 0 to 2)
p[k]=p[k] + k
end for
m = p[2] & 2
print m
11
-3
11
29
62
55
15
integer a,b,c
set a=1, b=3, c=7
a= a+b
if(a + b)
if( b + ( c^ a))
a=2
b =a
end if
end if
print a + b +c
12
22
11
Q119. For which of the following values of p, q, and r the output of the following pseudocode will be inside if?
integer p,q,r
p=p+q+r-9
q=(p+q)/2
if(p>q)
print "inside if"
else
print " inside else"
end if
p=12,q=7,r=-1
p=12,q=24,r=-5
integer x,y,z,a
set x=2,y=1,z=5
a=(x AND y) OR (z+1)
print a
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
52
29
41
36
Q122. What will be the output of the following pseudocode for b [] ={11, 12,18,28,45} and n=5?
integer fun(integer b[], integer n)
integer x
if(n EQUALS 1)
return b[2]
else
x=fun(b, n-2)
end if
if (x > b[ n - 2])
return x +2
else
return b[n -2]
end if
end function fun ()
20
45
28
18
Q123. what will be the output of the following pseudocode for a=6, b=1?
integer funn(integer a, integer b)
a= a + a
b= b + b
return a + b
end function funn()
16
14
12
23
Q124. What will the output of the following pseudocode for a=50
Integer fun(integer a)
Integer b
Set b=10
return a-b
End function fun( )
40
60
50
64
3 6 12
7 7 14
6 6 12
6 6 12 18
Q128. What will the output of the following pseudocode for b=18 ?
Integer calculate(integer b)
If (b EQUALS 1)
Return 0
Else
Return 5 + calculate(b/2)
End function calculate ()
34
20
21
56
it will print the sum of the elements of the second row of given 2-D array
it will print the sum of the elements of the first column of given 2-D array
it will print the sum of the elements of the second column of given 2-D array
it will print the sum of the elements of the first row of the given 2-D array
integer array1[6],p,j,q
set p=3
set array1[6]={3, 6, 10, 12, 23, 33}
for (each j from 0 to 5)
if ((array1 [j] MOD p) EQUALS 0)
p = array1[j] - (p * 3)
end if
q= p+ array1[j] - 3
end for
print q
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
64
44
34
54
integer a, b
set a=2,b=1
for (each a from 0 to 2)
for (each b from 0 to a)
print "laptop"
end for end for
Q133. For the following pseudocode, what should be typed in the black space?
integer Fibonacci(integer n)
if (n EQUALS 0)
return 0
else if(n EQUALS 1)
return 1
else
return (Fibonacci(n-1) + Fibonacci(........blank space...... ))
end function Fibonacci( )
n-3
n-2
n-1
integer a, p
set a=5
a= a+1
a= a*2
a= a/5 + 6
print p
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
22
20
24
26
integer a, b
set a=1, b= 1
a= ( a ^ 1) & (1 ) + (b ^ 1) & (1)
print a+ b
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise , the corresponding result bit is set to 0
The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
integer a, b, c
set b= 300, a= 5, c= 1
if( b> a)
b= a
else
a= b
end if
for ( each b from 0 to 5)
a= a+ 1
end for
print a + c
15
13
12
integer a, b
set a=10, b=10
a= a & b
b= b & 10
a= a& b
b= b & 10
print a + b
[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit
of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
20
integer a, b, c
set b=300, a= 5, c= 1
if ( b> a)
b=a
else
a= b
end if
for (each b from 0 to 5)
a= a+ 1
end for print a + c
13
12
15
integer i, j, k, m
set j=16, i=8,k=2,m=1
if( ( j^ i) mod k EQUALS 0)
m= m+ 1
else
m= m-1
end if
print m
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1
The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0]
integer x
set x=15
while (x EQUALS 15)
print "STUDENT"
jump out of the loop
end while
integer a[5], k
set a[5]= {1, 2, 3, 4, 5}
for( each k from 0 to 4)
if (k mod 2 equals 0)
print a[k]* 2
else
print a[k]
end if
end for
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
14385
1 2 6 4 10
2 2 6 4 10
character arr[ ]
integer size
set arr[ ]={'A', 'B', 'c', 'd', 'E', 'f'}
size= sizeof(arr)/sizeof ( arr[0] )
print size
[Note: sizeof is used to compute the size of its operand. It returns the size of a variable. It can be applied to any data type, float
type, integer.when sizeof ( ) is used with the data types, it simply returns the amount of memory allocated to that data type]
integer a, b, c
set b= 1, a= 5, c= 1
if ( b < a)
b=a
end if
for(each b from 0 to ( 1 ^ 2^ 3))
b= b + 1
end for
print b
[Note: The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
integer x, y, z
set x= 0, y= 1
for ( each z from 0 to 2)
x= x + y + z
end for
print x
integer i
set i = 100
if (i mod (1^ 2) EQUALS 1)
i= i+9
else
i= i -11
end if
print i
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
118
109
89
integer a, p
set a=5
a=a+1
a=a*2
a=a/2
p=a/ 5 + 6
print p
23
19
integer j,m
set m=1
integer a[4] = { 1,1,2,2}
a[0] = a[0] + a[1] + a[2] + a[3]
a[1] = a[0] + a[1] + a[2] + a[3]
a[2] = a[0] + a[1] + a[2] + a[3]
a[3] = a[0] + a[1] + a[2] + a[3]
m = a [3]
print m
45
20
40
30
integer a, b, c, d
set a= 3, b= 1
for (each c from b to b + 1)
a= a+ 1
if (1)
continue
for (each d 0 to 1)
a= a + c + d
if ( a> d)
jump out of the loop
end if
b= b + a - c + d
end for
end if
end for
print b + a
[Note - continue :when a continue statement is encountered inside a loop, control jumps to the beginning of the loop for the next
iteration ,skipping the execution of statements inside the body of the loop for the current iteration
If (X) gets executed if the value inside if( ), ie, x is not zero]
6
1
integer a, b, c
set a=1, b= 6,c= 12
if ( a> b)
if (a> c)
print c+ b
else
print b
end if
else
print b + 1
end if
integer a, b, c
set a= 3, b= 1
for (each c from b to a)
if ( a + b > 0)
b=a
continue
end if
a= a + b
a= a + 1
end for
print a
[Note - continue :when a continue statement is encountered inside a loop, control jumps to the beginning of the loop for the next
iteration ,skipping the execution of statements inside the body of the loop for the current iteration]
Q154. What will be the output of the following pseudocode for s= 12, k= 4, m= 2?
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
16
12
44
32
integer a, b,c
set a=1, b=1
for (each c from 4 to 7)
a= a+1
if (a < 10)
a= a-1
continue
end if
a= a+ 2
end for
print b + a
[Note - continue :when a continue statement is encountered inside a loop, control jumps to the beginning of the loop for the next
iteration ,skipping the execution
of statements inside the body of the loop for the current iteration]
integer a, b, c
set a=3, b=2
if (b-1)
for (each c from 1 to 3)
a= a-1
end for
for(each c from 1 to 3)
a= a + b
end for
end if
print a+ b
[ Note: If (X) gets executed if the value inside if( ), ie, x is not zero]
[Note-:&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
| | : Logical OR - The logical OR operator (| | ) returns the boolean value True (or 1) if either or both operands is True and returns
False( or 0), Otherwise ]
integer a, b, j
set a=10, b= 18
for (i=6 to a-1) increase i by
b= ((b*2)/ 2) + 3
print b
end for
21 24 27
21 24 27 30 33
18 21 24 27
21 24 27 30
integer a, b, c
set a=13, b= 9, c= 6
if (a< b)
if (a < c)
print a
else
print c
end if
else if (b < c)
print b
else
print c
end if
69
6
13
integer i, a, j
set i=6, a=23
j= i + a && i / a && a/ i + i
if (j)
print j
else
print j + j
end if
[&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)
If (X) gets executed if the value inside if( ), ie, x is not zero]
20
integer a, b , a, d
set a=3, b= 1, c=1
for (each d from 1 to 3)
a= a-1
if(d> 2)
a= a- b
b=a
if (d < 2)
jump out of the loop
end if
a= a + 1
end for
print a + c
-5
integer a, b
for (each a from 1 to 2)
b= 17
print b + a - a * a
end for
print a + 1
17 17 16
17 15 4
123
17 4 15
integer k
set k=6/7 + 3 - 3
if ( k < = 0)
if ( k equals 0)
print "test1"
else
print " test2"
end if
else
print "test3"
end if
print " test completed"
test completed
integer j, m
set m=1
integer a[4]= {0, 1,0,2}
a[0] = a[0] - a[2] + a[3]
a[1] = a[0] -a[3]
a[2]= a[1] - a[2]
a[3] = a[2]
m = a[3]
print m
integer n
set n=15
while( n <=15)
n= n + 6/3
print " biography"
continue with next iteration
end while
it will print biography 13 times
13
34
11
12
integer compact(integer a)
if( a <= 45)
compact( compact (compact (a * 5 + 1)))
end if
return a*2
end function compact ()
22
45
56
44
Q168. What will be the output of the following pseudocode for a=100?
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
99
98
101
87
11
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
talp
lIa
Atpl
Aptl
Q171. What will be the output of the following pseudocode for a1= 3 and b1= 4?
54
56
77
57
integer p
set p = 1
while( p + 2 <= 4)
print p
p= p+1
jump out of the loop
end while
Integer x
Set x= 3
do
X= x-1
Print x * 4
Continue with next iteration
Print x * 7
X= x-1
While ( x not equals 2)
End do while
Print x * x/6
[Note:- A do-while is a control flow statement that executes a block of code at least once and then repeatedly executes the block ]
78
80
96
70
Integer j, m
Set m= 1
Integer a[4] = { 1,1,2,2}
a[0] = a [0] + a [1]
a[1] = a [1] + a [2]
a[2] = a [2] + a [3]
a[3] = a [3] + a [0]
m= a[3]
Print m
Integer f, k, j
Set f= 9, k= 55
j= f + k / 8
if( j + 1 >= 8)
f=f+1
Else
K=k+1
End if
Print f + k
65
67
78
66
Integer k, a, p
Set k = 5, a =234
P= k + a && k / a || a/ k + k
If(k)
Print “it is working”
Else
Print “it is not working”
End if
[Note:-&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)
| | : Logical OR - The logical OR operator (| | ) returns the boolean value True (or 1) if either or both operands is True and returns
False( or 0), Otherwise]
No output
It is working
It is not working
[Note - continue :when a continue statement is encountered inside a loop, control jumps to the beginning of the loop for the next
iteration ,skipping the execution
of statements inside the body of the loop for the current iteration]
[ Note:-&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)
If (X) gets executed if the value inside if( ), ie, x is not zero]
20
-4
-3
Integer i, j, k
sett i= 1, 2, 3
set j= 1, 2, 3
set k=1, 2, 3
print i, j, k
1,2,3
1,1,1
123,123,123
3,3,3
45
67
65
78
integer a, b
set a=5, b= 8
do
print b/ a
while (a/ b)
end do while
1.6
Q183. For which of the following options, the pseudocode will print the square of variables ' a'?
integer a
if( a mod 2 not equals 0)
if( a > 12)
print a * a
end if
end if
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
integer a, b, c, d
set a= 3, b= 1
for (each d from 1 to 3)
for (each c from 1 to 2)
if( c < d + 1)
a= a- b
else
a= a+ b
end if
end for
end for
print a
-2
integer k, p, i
set k= 2, p= 6
int i= k / p + 3 * k/ p
if (i)
print " you are promoted "
else if ( i not equals 0)
print " you are not promoted"
else
print " you better try next time "
end if
[ Note:-If (X) gets executed if the value inside if( ), ie, x is not zero]
integer a, b, c
set a=11, b= 21
for(each c from 16 to 17)
if ( c-10 > 8)
if (1 && 1)
a= a + c
end if
a= a + 1
else
a= 0
end if
end for
print b + a
[Note:- && : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)
If (X) gets executed if the value inside if( ), ie, x is not zero]
11
14
32
50
integer a, b
set b= 2
set a= b + 3
if (a && b - a && 1)
a=a +1
end if
print a
[Note:-&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
integer n, c
set n= 128, c= 4
while( n NOT EQUALS 0)
n= n / 10
c=c-1
end while
print c
-1
integer a[5]
set a[5]= { 1,2,3,4}
integer m, j
set m= 1
for ( each j from 0 to 3)
m= m + a[j] + a[ j] + 6
end for
print m
43
45
23
46
Q190. How many times the following pseudocodes will print hello?
integer k, p, j
set k= 1, p= 4
int j= p + k / 2
if ( j equals p)
print "hello"
end if
j= p + k / 5
if ( j not equals p)
print " hello "
end if
print " hello "
three times
one times
two times
integer k, p
set k= 56
p = k + 8 - 78 / 8 * 4/7 - 5/ 2
if (p )
print "hello "
else
print " bye"
end if
[Note: If (X) gets executed if the value inside if( ), ie, x is not zero]
hello
hello bye
bye
integer a, b, c
set a= 1, b= 2
for (each c from 216 to 217)
if( c - 200 > 100)
if( 1 && 1)
a= a + c
end if
a= a+ c
else
a=0
end if
end for
print b + a
[Note:-&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
8
integer a, b, c, d
set d= 6
for( each a from 1 to 2)
for(each b from a to 2)
for (each c from b to 2)
print d
end for
end for
end for
666666
666
6666
integer a, b, c
set a= 108, b= 2, c= 3
if (( a MOD 9) EQUALS 0)
b= b + (a MOD 2)
print b
else
c= c + ( a MOD 7)
print c
end if
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1]
integer i
set i=45
if( i mod 2 EQUALS 0 OR i mod 2 AND i)
print i mod 2
else
print i
end if
[Note: MOD finds the remainder after the division of one number by another. For example, the expression "5 MOD" would
evaluate to 1 because 2 leaves a quotient of 2 and a remainder 1
| | : Logical OR - The logical OR operator (| | ) returns the boolean value True (or 1) if either or both operands is True and returns
False( or 0), Otherwise]
45
p is a pointer to the first node of the linked list, Which of the following operations is performed by the function fun?
function fun detects a loop in the linked list, it return 1 when a loop is found
and 0 when no loop is found
Function fun checks whether a linked lists is sorted or not. It returns 0 when
the list is not sorted and 1 when it is sorted
Q198. What will be the output of the following pseudocode?
integer a
string str1
set str1= " momo"
for (each a from 1 to 2)
str1= str1 + " mm"
end for
print (stringLength(str1))
it will print 23
Q200. How many times the following pseudocode will print "btech"
integer a, b
for(each a from 0 to 3)
for(each b from 0 to a)
print "btech"
end for
end for
3 times
9 times
10 times
11 times
Q201. What will be the output of the following pseudocode for a= 3 and b= 4?
20
10
integer a[10]
set a[10]= { 1,2,3,4,5,6,7,8,9}
for(each i from 1 to 4)
if (a[ i / 2])
print a[ i * 2]
else
print a[ i + 2]
end if
end for
2468
12345
2680
3579
integer a,b
set a= 0
a= a^ 1
a= a^ 2
a= a^ 3
print a
[Note: The bitwise exclusive OR operator(^) compares each bit of its first operands to the corresponding bit of its second operator.
The corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0].
integer h
set h= 42
do
print h
h ++
if (h > 45)
jump out of the loop
while()
end do while
42 43 44 45
43
42
42 44 45 46
[Not:&& : Logical AND - The logical AND operator (&& ) returns the boolean value True (or 1) if either or both operands is True and
returns False( or 0)]
Respect elders
elders
Respect
integer k, m
set k= 1, m= 9
if(k + 8/m)
print m
m= m + 1
if(k* 8 / m)
print k
k= k- 1
for(each k from m to 8) decrease k by 1 in each iteration
print k
end for
9 10 9 9
9 10 8 9
9 10 9 8
9 10 9 10
integer s
set s=78
while(s EQUALS 78)
if ( s< 89)
s= s + 1
continue with next iteration
print "welcome"
else
jump out of the loop
end if
end while
Q209. What will be the output of the following pseudocode for a=3?
integer fun(integer a)
integer arr[]={10,7,2,6,1,2,3}
integer p, sum =0
for(each p from 0 to a-1)
sum = sum + arr [a]
end for
return sum
end function fun()
20
18
21
15
50
40
25
integer a, b,c
set b=3, a= 5, c=1
if( b < a )
b= a
end if
for(each b from 0 to (1^2^3))
b= b + 1
end for
print b
integer a, b
set a=15, b= 7
a= a mod (a-3)
b= b mod (b-3)
a= a mod 1
b= b mod 1
print a + b
0
15
Q213. What will be the output of the following pseudocode for a=2?
integer fun(integer a)
if(a>0)
return a+ fun(a-1)
else
return 0
end if
integer a, b,c
set b=5, a=2, c=2
if(a)
a=a-1
a=c
else
c=c+1
end if
if(a-1)
c=c+1
else
c=c-1
end if
print a+b+c
15
20
10
11
Q215. What will be the output of the following pseudocode f(x) x =777
1 Integer fun(Integer x)
2 if (x > 12)
3 fun (x / 9)
4 print x
5 else
6 for (each i from 1 to 3)
7 x=x+i
8 print x
9 end for
10 end if
10 end if
11 end Function fun( )
11 13 14 85 777
12 14 15 86 777
10 12 13 86 777
10 12 13 85 777
Q216. What will be the output of the following pseudocode for x = 4 and y = 2
1 Integer fun (int x, int y)
2 if (x > 1)
3 fun (x - 2, y + 2)
4 end if
5 print y
6 End Function fun( )
456
975
765
Q217. What will be the output of the following pseudocode for x = 45?
[Note: mod finds the reminder after the division of one number by another , For example , the expression "5 mod 2" would evaluate
to 1 because 5 divided by 2 leaves a quotient of 2 and reminder of 1]
Infinite loop
Q218. What will be the output of the following pseudocode for x = 343?
[Note: mod finds the reminder after the division of one number by another. for example , the expression "5 mod 2" would evaluate to
1 because 5 divided by leaves a quotient of 2 and a reminder of 1]
49
Q219. What will be the output of the following pseudocode for x = 23 and y = 222
Note: 1. ' << ' is Left shift operator
2. '&' is bitwise AND , the output of the bitwise AND is 1 if the corresponding bits of has represents is 1. It can be the result of the
corresponding bit is evaluated to 0.
3. '^' is bitwise XOR , the result of the bitwise XOR operator is 1 if the corresponding bits of the operator.
245
22
2223
1022
40
31
61
20
Q221. What will be the output of the following pseudocode for x = 108, y = 3 ?
1 Integer fun (Integer x, Integer y)
2 if (x > 1)
3 fun (x/y, y+3)
4 Print y
5 enf if
6 end function fun ()
12 9 6
12 9 6 3
0 6 36 108
6 12
hta
ath
hat
tah
64
66
62
68
1 Integer p, q, r
2 Set p = 0, q = 3, r = 14
3 if (1< p && (q+p) >(p+q))
4 r=q+r
5 End if
6 print p + q + r
17
19
28
14
tratStsart
tratrat
tratstartt
tratStart
0 12 0 12 13
12 24 36 48 60 61
0 12 24 25
12 24 36 48 61
32
288
12
38
61
72
64
Q230. What will be the output of the following pseudocode for the input pqr?
Note: Here NULL typically means the end of the string.
1 fun(char a )
2 if (a[0] EQUALS NULL)
3 Return
4 end if
5 fun(a + 1)
6 fun(a + 1)
7 Print (a[0])
8 end function fun
rrqrrqp
ppqqrr
rqppqr
24
16
12
14
41
25
30
14
29
10
1
15
-1
23
17
14
traversing an array
sorting an array
Q237. Which of the statements given in the options is correct regarding the following pseudocode?
1 if(x > y):
2 if(z > y):
3 if(z == x):
4 print ("two");
5 else:
6 print ("one");
7 else:
8 print ("three");
9 else:
10 print ("four");
36 43
23 16
71 64
39 32
Q239. Which one of the following gets generated by the given pseudocode for input n=5?
1 function(input n)
2 {
3 if (n < 2)
4 return n;
5 else return function (n-1) + function(n-2);
6 }
7
8
14
12
12 12 16 18 112
0 2 4 6 112
12 14 16 18 296
Q243. What will be the output of the following pseudocode for n = 243?
Note: mod finds the reminder after the divisions of one number by another. For example , the expression " 5 mod 2" would evaluate
to 1 because 5 divided by 2 leaves a quotient of 2 and a reminder of 1.
1 Integer abc (int n)
2 Integer a, b
3 if (n > 0)
4 a = n mod 10
5 b=b+a
6 abc = (n / 10)
7 else
8 return b
9 End abc ()
342
12 1
12 - 1
14 - 2
Infinite loop
120
100
80
56
4 28 60 23
19 27 54 63 23
4 18 31 43 23
4 18 31 43 26
12
22
16
26
17
12
-1
50
64
57
56
Answer Key & Solution
Section 1 - MCQ
Q1
12:30:30
Solution
n=45000;
h=45000/ 3600 = 12
s=30mod 60; = 30
12:30:30
Q2
non of these
Solution
It prints 1 then x=1*5 =5 ,loop get iterated and print 5 then x=5*5=25 25>20 so loop terminates.
Q3
7
Solution
Pre increment will be done before adding the values i.e 2+5 = 7
Q4
127
Solution
b=625/5 = 125
a=125+1 = 126
After that a incremented by 1 i.e. 127. a<4 (false) so 127 gets printed.
Q5
87
Solution
When i=1,c=73
When i=2,c=75
When i=3,c=78
When i=4,c=82
Q6
29
Solution
a=6=> 0110
b=8=> 1000
if 14<6 (False)
so a=6,b=8,c=15
therefore 6+8+15 = 29
Q7
2
Solution
p=3, q=1?
Binary representation :
Q8
4
Solution
p=1=> 0001
q=2=> 0011
r= 0=> 0000
1<2 (TRUE)
p=2
if(2 > 2) (FALSE)
Therefore 2+2+0 = 4
Q9
114
Solution
In this q^q>1 statement, q > 1 will be evaluated first and enters if block.
Q10
7
Solution
When the array element is less than or equal to 1, the value of m is changed to the current array value.
Output : 7
Q11
134
Solution
Q12
6
Solution
If the condition gets failed so only the q value will be updated.
Q13
3
Solution
So p-value is updated as 1.
Q14
15
Solution
Output is 15. Outer if block condition is true but inner if block condition is false, so only qq value is updated to 6.Therefore 5+6+4 = 15.
Q15
9
Solution
As a result 3+3+3 = 9.
Q16
4
Solution
Inside for loop, the value of 'a' is added and subtracted by 'c', so there is no change in the 'a' value.
As a result 3+1 = 4.
Q17
31
Solution
10=>1010
c => 1100
a=8+6+12 =26
c= 26 & 5 => 0
As a result 26+5+0=>31
Q18
6
Solution
Relational Operators have higher precedence than arithmetic operators. So 'p' and 'q' values will get updated to 2.
As a result 2+2+2 = 6
Q19
19
Solution
Inside for loop, the value of b will be updated to 14 for each iteration.
Q20
6
Solution
Q21
32
Solution
Iteration 1:
a=19
a=19+5=>24
Iteration 2:
a=23
a=23+5=>28
Iteration 3:
a=27
a=27+5=>32
As a result 27+5 = 32
Q22
14
Solution
a=3=>0011
b=4=>0100
c=6=>0110
a=3=> 0011
7 => 0111
Inside if block,
Q23
43
Solution
First, if block will get executed and update the value of 'p' and 'r'.
Q24
21
Solution
Because the outer if block condition fails, the variable's value remains unchanged.
As a result 7+7+7 = 21
Q25
2
Solution
Because the outer if block condition fails. So, pp and qq value gets updated.
pp=1+1 => 2
qq=2+1 => 3
Q26
15
Solution
Because the inner if block condition fails, the variable's value remains unchanged.
So 2+13 => 15
Q27
13
Solution
Iteration 1:
c=5
a=1+5 = 6
Iteration 2:
c=6
a=1+6 = 7
Iteration 3:
c=7
a=1+7 = 8
Iteration 4:
c=8
a=1+8 = 9
Iteration 5:
Q28
18
Solution
In iteration 1:
a=1,c=6
a=1=> 0001
c=6=> 0110
a=0,c=6
a=6,c=7
a=6=> 0110
c=7=> 0111
a=6,c=7
a=6+7 => a= 13
As a result, 13+5 = 18
Q29
-3
Solution
As a result, 2-1-4 = -3
Q30
0
Solution
After duplicating the array's values, all of the array's values and m are set to '0.'
Q31
2
Solution
The value of pp will be 0 at the end of the for loop, and 1 inside the if block.
As a result, it displays 2.
Q32
5
Solution
The if block in the for loop is only run for the array values 0 (update m=1) and 4 (update m=5).
Q33
21
Solution
Q34
4
Solution
Q35
2
Solution
Q36
5
Solution
Q37
2
Solution
As a result, it displays 2.
Q38
13
Solution
Q39
2
Solution
Q40
22
Solution
First If block gets executed and set 'c' as 14 and second if blocks get failed and set 'c' as 7.
Q41
27
Solution
Q42
20
Solution
Output: 8+4+8 = 20
Q43
3
Solution
Value of 'c' copied to 'a', then 'a' value copied to 'b' and 'c'.
Q44
1
Solution
Output: 1
Q45
26
Solution
Initially a= 2, b= 4, c= 8
8 < 4 (FALSE)
As a result, 4 + 4 + 18 = 26.
Q46
5
Solution
Initially, m=3.
Q47
2
Solution
Initially p= 1, q= 1, r= 1
So, 0+1+1 = 2.
Q48
24
Solution
For loop executes three-time and set 'q'= 16 for all the iterations.
So, 8+16=24
Q49
4
Solution
As a result, it displays 4.
Q50
19
Solution
So, 5 + 14 = 19
Q51
21
Solution
Output: 1+0+20 = 21
Q52
2
Solution
Initially p=1,q=1
Output: 3 ^ 1 => 2
Q53
8
Solution
Initially p=5,q=2
2&5 = 0
5^3 = 6 (p=6)
Output : 6 + 2 = 8
Q54
15
Solution
m= 8 + 7 => 15
Q55
2
Solution
Initially a[4] = { 1, 1, 1, 2}
a[3] = 2
m=2
Q56
3
Solution
Initially p= 2,q= 0, r= 0
Q57
-1
Solution
Initially a= 2, b= 2;
Iteration 1:
c=1,a=2
Iteration 2:
c=2,a=-1
Iteration 3:
c=3,a=0
Q58
2
Solution
Finally, 2 gets printed.
Q59
11
Solution
Initially a=6, b= 2, c= 7
After running the for loop, the value of 'a' is set to 5 (the loop runs until the value of 'c' is 5).
Output: 9+2 = 11
Q60
4
Solution
Iteration 1:
0>1(FALSE)
Iteration 2:
1>0 (TRUE)
Iteration 3:
2>1 (TRUE)
Iteration 4:
3>2 (TRUE)
Q61
7
Solution
Solution
First if blocks get failed, but second if block gets executed and set c=12 and a=31
Q63
2
Solution
Initially p=2,q=3
Q64
16
Solution
15 => 1111
1 => 0001
15&1=>0001 (c=1)
Q65
11
Solution
Initially a=5, b= 4, c =7
After executing first for loop, 'a' set to 1+ 6 = 7 (loop execute until c value is 6)
Solution
Q67
3
Solution
Initially p=1,q=1,r=2
Q68
20
Solution
After executing for loop 'b' set to 10 (b=10) and 'b' value copied to a.
As a result 10+10 = 20
Q69
1
Solution
Initially m=1
There are no changes in the value, because both if block condition fails.
As a result, it displays 1.
Q70
30
Solution
Initially p=6, q= 9, r= 7
7=>0111
6=>0110
&=>0110 (7 & 6 = 6)
9=>1001
7=>0111
^=>1110 ( 9 ^ 7 = 14)
Q71
12
Solution
While j=3 ,
The value 'm' is used as the array's third index value, which is 12.
Q72
4
Solution
Initially a=1, b= 3, c= 2
If block condition gets failed,so 'b' value is set to 1. (b=3&1 => b=1)
As a result, 1+1+2=4
Q73
654
Solution
Initially, i=3.
Iteration 1:
Iteration 2:
Iteration 3:
Solution
Initially a=2,y=3
Iteration 1:
a=2+3 =>a=5
Iteration 2:
a=5+3 =>a=8
Iteration 3:
a=8+3 =>a=11
Q75
It will print the reverse number from 12 to 0 except 1
Solution
In next iteration a=12, Inside loop 'a' value decrements and printed 11.
The same process is repeated and prints 10,9,8,7,6,5,4,3 until 'a' value is 3.
When a=3, 'a' value decrements and prints 2 then the loop terminates.
Q76
1
Solution
a[3]= 2 // {0,2,2,2}
m=2
Q77
None of the mentioned option
Solution
Recursive function call: fun(22,4,2) --> fun(20,6,4) --> fun(16,8,6) --> fun(10,10,8) --> fun(2,12,10) --> fun(-8,14,12)
In fun(-8,14,12) function call do nothing and control transfer to previous call fun(2,12,10).
In fun(2,12,10) function call prints 12 and control transfer to previous call fun(10,10,8).
In fun(10,10,8) function call prints 10 and control transfer to previous call fun(16,8,6). This process repeats upto first function call
fun(22,4,2)
Q78
-3
Solution
In fun(2) function call -3 value returned to fun(23) and from that again -3 returned to fun(125) and gets printed.
Q79
-5
Solution
Q80
14 50 40 30 9 4 -1
Solution
When an integer is divided by another integer, the result is an integer. 60/15=4, so the loop executes four times.
Iteration 1:
a=60-10=> 50 .
b=15-5=>10 .
(Similarly, the while loop is repeated three times until b is less than or equal to zero, and then the value of 'a' is printed by decrementing it
by ten times).
Then c value update again c= 14+0-5 => 9 gets printed. Similarly, the for loop is repeated until 'i' becomes 4.
Q81
42
Solution
Initially x= 75. 75-35(40) which is greater than 18 (75/4). So fun() returns 37+5 i.e 42.
Q82
14:12:6
Solution
Initially a1=2, b1=45, c1=36, a2=11, b2=26, and c2=30. c=66 (36+30). b=1 (66/60 ). c= 6 (66 mod 60). b= 72 (1+ 45 + 26). a= 1 (72/60) . b=
Q83
5
Solution
Four greater than five (FALSE), five greater than zero (TRUE). Logical OR operator(||) returns the boolean value TRUE or (1) if any of the
conditions are TRUE. Inside if block, 'b' assigned with 'a' value (b=5) and a=0. Next, if block condition gets failed and prints 0+5 = 5 .
Q84
5
Solution
In bitwise exclusive OR ,if one bit is 0 and the other bit is 1, the corresponding result bit is set to 1.
If you apply bitwise exclusive OR to the same number, the outcome is zero.
So else block gets executed and assign b=2. As a result, 3+2 =5 gets printed.
Q85
13
Solution
Initially a=1, b=4, c=3. Logical AND operator (&&) returns the boolean value TRUE or 1 if all the conditions are TRUE.
Because both the if block conditions are TRUE in this case, it is executed and the values a=2 and b=8 are updated.
Q86
5
Solution
integer a=1.
Iteration 1:
1<5 (TRUE)
a=3
Iteration 2:
3<5 (TRUE)
a=5
Iteration 3:
5<5 (FALSE)
Q87
15
Solution
Initially m=9, n=6. m updated to 10 by incrementing m by 1 and n updated to 5 by decrementing n by 1. Then m=10+5 = 15. Here 15 > 5
Q88
a=3, b=4, c=5
Solution
Value 'a' should be greater than 'b' or 'c' to execute first if block. Then the sum of 'a+b' should be greater than 'c' and 'b' should be less than
'c' to execute the next if block. So a=3, b=4, c=5 is the only option that satisfies the above constraints.
Q89
2
Solution
Initially a=2, b=2, zero is considered as FALSE value, so else block executes and update a=0. As a result, 0+2 = 2 gets printed.
Q90
none of the mentioned options
Solution
Initially n=1, loop runs only once and assign b= 1 (1 mod 4 = 1) .Modulo operator gives reminders. If block condition gets failed and prints
Q91
343 342
Solution
Initially, n=343, m= n
Logic inside the while loop is used to reverse the number. If the reversed number is the same, the next number will be printed; otherwise,
Q92
10
Solution
Initially a=3, b=2, c=1, d=10
2 mod 24 =2 , 2 mod 8 =2 (both the values are not equal to zero, so if blocks wont get executed and prints 'd' value (10).
Q93
calculates x+x*y
Solution
In this program fun() is called repeatedly and added up until y becomes zero. Repeated addition is called multiplication i.e x*y.
Q94
8
Solution
5=> 0101
2=> 0010
4=> 0100
Q95
23
Solution
Initially a=4,b=9.
If block executes and update a=4+9 (13), a= 13+9 (22), b=9+22 (31).
22=>0001 0110
09=>0000 1001
31=>0001 1111
Q96
40
Solution
funn(2,2)=> 2+funn(0,0)+2 ,
funn(0,0) => 0 ,
Q97
7
Solution
Initially p=1,q=1,r=3,
p=1+(1^3)&1 = 1
p= 1+((1 ^ 3)&1) = 1
As a result, 1+3+3 = 7.
Q98
14
Solution
Q99
1.000000
Solution
Given condition is true so it returns a value 1. Double prints the value with 6 decimal places, so 1.000000 gets printed.
Q100
25
Solution
In fun(20,25,30), recursive function call made for fun(-10,25,27) => p less than 1 so moves to previous call and execute remaining
Q101
It will print Hello one time
Solution
Initially, i=3, j=5, j less than 6 condition is true, so it prints "Hello" and increment j value. Now j less than 6 condition is false. So,"Hello" was
Q102
405
Solution
Initially p=15,q=3
q= 15 mod 5 =>q= 0
Q103
14
Solution
Q104
10 15 20 25 30 6 35 7
Solution
In fun(5) => does nothing and backtrack to fun1(10) [pending instruction get executed] prints n value (i.e) 10 and fun1(10/5)
[fun1(2)]called and do nothing.Again recursive call backtrack to fun1(10) and backtrack to fun(15) and do same process repeatedly and
prints 15,20,25.While backtrack to fun1(30) [pending instruction get executed] prints n value (i.e) 30 and fun1(30/5) [fun1(6)]called and
then 6 gets printed. Similarly recursive call gets executed and prints 35,7.
Q105
18
Solution
Initially x=7, y=9
z= 7+9 = 16
y = 16 mod 7 => 2
x= 7+2 => 9
y =9+16 => 25
Iteration 1:
y=25-3 => 22
Iteration 2:
y=22-4 => 18
Q106
-2
Solution
Initially a=4, b=2, if condition gets failed and return 2-4 (-2) gets printed.
Q107
5
Solution
integer a=1.Iteration 1: 1<5 (TRUE)a=3, Iteration 2: 3<5 (TRUE) a=5 , Iteration 3: 5<5 (FALSE) So, 5 gets printed.
Q108
14
Solution
Q109
5
Solution
Q110
-7
Solution
fun(-6), -3<0 (True), it returns -6+1 (-5) to previous function call. So fun(-6) replaced with -5. As a result fun(-5) is called. This process
fun(12)=6,
fun(6)=0,
fun(0)=-6,
fun(-6)=-5,
fun(-5)=-4,
fun(-4)=-3,
fun(-3)=-9,
fun(-9)=-8,
Q111
2
Solution
Initially c=2, a=9, b = 7, b= 7 % 2=> b=1 , a= 9%2 => 1. As a result, 2 gets printed.
Q112
5
Solution
Initially, the string length is 8. At 5th index Null included. Null is considered as an end of a string. So now the string is "ABCDE", current
string length is 5.
Q113
10 36
Solution
Initially a=3, b=2, c=0. Inside while loop, c updated to 5, a updated to 8.Inside else block b updated to 10 and gets printed. In the next
iteration, c updated to 18, a updated to 26. Inside else block b updated to 36 and gets printed. In the next iteration, c updated to 62, a
Q114
6
Solution
Initially p[5]={1,4,5,6,7}.
1=> 0001
4=> 0100
&=> 0000 (0) . First If block wont execute.
5=> 0101
7=> 0111
&=> 0101 (5). If block gets executed and update m value by 6 and gets printed.
Q115
0
Solution
Initially p[3]={1,7,6}. All the values in the array are added to the index value and updated in the array inside the loop.(i.e) {(1+0),(7+1),(6+2)}
= {1,8,8}.
8=> 1000
2=> 0010
Q116
29
Solution
Iteration 1:
val=0+10 =10
val=10+10 =20
Iteration 2:
val=1+10= 11
val = 11+10=21
Similarly, the loop executes and increases 'val' value by 1 till 'i' is less than or equal to 9.
Q117
5
Solution
Q118
11
Solution
Initially a=1,b=3,c=7. a=1+3 => 4.
7 = 0111
4 = 0100
^ = 0011 (3). 3 + 3 =6 , so it is considered as true and if blocks executes and update a & b value (a=2, b=2) . As a result, 2+2+7 = 11 gets
printed.
Q119
p=12,q=7,r=-1
Solution
q=(9+7)/2=> q=8
Q120
1
Solution
The logical-AND operator produces the value 1 if both operands have nonzero values.
The logical-OR operator performs an inclusive-OR operation on its operands. The result is 0 if both operands have 0 values. If either
Initially x=2,y=1,z=5
Q121
36
Solution
The current index array value is assigned inside the for loop by adding the previous array value by two.
Q122
28
Solution
Finally, 28 gets printed.
Q123
14
Solution
Here just a and b value updated by adding it twice eg: a= 6+6 =12, b=1+1 = 2 and finally 12+2 = 14 gets printed.
Q124
40
Solution
Q125
64
Solution
Initially a1 =8.
When you divide an integer by an integer, you'll get an answer in an integer.(5/7 =0).
8+0 => 8
Q126
6
Solution
Initially x= 0, y= 1
Iteration 1:
x= 0, y= 1,z=0
Iteration 2:
x= 1, y= 1,z=1
Iteration 3:
x= 3, y= 1,z=2
Iteration 4:
'z' value exceeds 2 so the loop terminates and prints the value 6.
Q127
6 6 12
Solution
While(1) means infinite loop, the loop only breaks if the value of 'p' is larger than 23.
Iteration 1:
r=6-3 => r= 3
Else block get executed and updated q=9-3 => q=6 (q value gets printed)
Iteration 2:
r=9-6 => r= 3
Else block get executed and updated q=12-6 => q=6 (q value gets printed)
Iteration 3:
r=12-6 => r= 6
Else block get executed and updated q=18-6 => q=12 (q value gets printed)
Iteration 4:
r=18-12 => r= 6
Q128
20
Solution
Function call starts from calculate(18), then it calls itself until 'b' reaches 1. Function returns 0 to calculate(1) ,calculate(2) return 5 by
adding 5+0. Same process repeated upto calculate(18). In calculate(18), 5+15 = 20 . Final value(20 ) returned to main method and gets
printed.
Q129
it will print the sum of the elements of the first row of the given 2-D array
Solution
Inside for loop, when 'k'=0, j varies from 0 to 2 i.e a[0][0],a[0][1] and a[0][2]. All the zeroth row value gets aggregated and loop breaks. Final
Q130
1
Solution
'b' (1) right-shit by 1 , set b value as 0.Then c value left-shift by 0 will not update c value.
Q131
54
Solution
Inside for loop, initially j=0,array1 [0]%3 =0 (True) so it executes if block and update q and p value. The same process is repeated until j
value reaches 5.
While j=5 , p= 24, q= 54 (then loop terminates and print q value as 54)
Q132
it will print 'laptop' 6 times
Solution
Inside for loop, while a=0, inner for loop runs once.
Totally loop runs six times and the "laptop" gets printed six times.
Q133
n-2
Solution
The fibonacci series number is the sum of the two preceding ones. So call function Fibonacci(n-1) + Fibonacci(n-2).
Q134
0
Solution
Because the p value has not been initialized, the compiler will use 0 as the default value and so 0 gets printed.
Q135
24
Solution
r updated to 6
s updated to 18
r updated to 12
s updated to 24
t updated to 12
r updated to 24
s updated to 36
t updated to 24
Iteration 4: (12 > 23)(False) So it compares s and t and prints t value as 24.
Q136
1
Solution
When two identical numbers are bitwise XORed, the outcome is zero.
eg: 1 ^ 1 =0
1 => 0001
1 => 0001
^ => 0000
Q137
it will swap the values of first and second and double
Solution
Both values are swapped here, and the second*2 instruction doubles the second value.
Q138
12
Solution
Inside loop:
Q139
20
Solution
When two identical numbers are bit-wise AND, the outcome is the same number.
eg: 10 & 10 = 10
10 => 1010
10 => 1010
Q140
12
Solution
The value of b is 300, a is 5 and c is 1Check the condition whether b is greater than a, it becomes true so the value a is assigned to be, b
becomes 5For loop starts from 0 and ends with 5, for every iteration we are going to add 1 to the variable a and assign it back to a.After
the iteration of for loop, the value of a becomes 11 Print the sum of a and c, the output is 12
Q141
2
Solution
The value of j is 16, i is 8 k is 2 and m is 1when we perform j ^ i, it result in 24 and performs mod by k which is 2, it result in 0 then compare
Q142
it will print "STUDENT" only one time
Solution
The value of x is 15when we check the condition in the while loop, it is true so it prints the student once and breaks the loops, the answer
Q143
2 2 6 4 10
Solution
The iteration of the for loop starts with 0 and ends with 4 itself, only for even indices, the value will be multiplied by 2 and results in 2 2 6 4
10
Q144
6
Solution
The size of the array arr is 6 , the size of arr[0] is 1 and the totally array has 6 characters. When we divide 6 by 1, it becomes 6.
Q145
1
Solution
The value of b is 1, a is 5 and c is 1Check the condition whether b is less than a, it becomes true so we assign the value a in b, the value of
b becomes 5Now for loop starts iteration from 0 to 1^2^3, the variable b is assigned for the for loop and starts the iteration from 0 when
we perform 1^2^3 it results in 0, the loop condition executes once, then the value of b is updated as 1.
Q146
6
Solution
the value of x is 0 and y is 1for loop will iterate from 0 to 1 because it will consider the condition as z <= 2 so 2 will not be considered, 0th
iteration x is 0, y is 1, z is 1, Sum of these 3 values result in 1 which is stored back in x, 1th iteration x is 1, y is 1, z is 1, Sum of these 3
values result in 3, which is stored back in x, 2nd iteration x is 3, y is 1, z is 2, Sum of these 3 values result in 6, which is stored back in x
Q147
109
Solution
we have to perform mod operation for i and the answer for exor operation for 1 and 2
The result for exor operation for 1 and 2 is 3, the value of i is 100 when we perform 100 mod 3, the result will be 1 which equals to 1 as per
Q148
7
Solution
The value of a is 5
Then a is divided by 5 which results the answer as 1 and added with 6, it becomes 7 which is assigned to p
The output is 7
Q149
18
Solution
Hint 1The value of a1 is initialized as 15Then a1 is subtracted by 1, it becomes 14Next a1 is multiplied by 2 and added with 8 so it
becomes 36Next a1 is divided by 2 and added with the result of 9 * 5, it becomes 63then 63 divided by 5 it becomes 12 then added with 6,
it becomes 18 which will be assigned to p1. Finally, when we print p1, it prints 18 as output
Q150
40
Solution
The output is 40
Q151
6
Solution
The value of a is 3 and b is 1Outer for loop iteration starts from 1 and ends with 2, for every iteration, the value of a is added with 1. After
the iteration of for loop, the value of a is updated as 5. Finally, it prints the output as the sum of a and b which is 6
Q152
7
Solution
Q153
3
Solution
The value of a is 3 and b = 1for loop starts from 1 and ends with 2c=1the sum of a and b is 4 is greater than 0 if condition becomes true
so the value of a is assigned to b, b becomes 3 and the loop gets continuedNow the value of b is 3 c = 2the sum of a and b is 6 is greater
than 0 if condition becomes true so the value of a is assigned to b, b becomes 3 and the loop gets continued till it c <= 3. The output prints
Q154
16
Solution
By checking the condition the sum of s and m is not greater than 1 so it returns the value 6 to the previous recursive call
and the value 6 is returned to previous recursive all and that function returns the sum of 10 and 6 and finally 16 is returned by the function
Q155
2
Solution
Initially a=1,b=1. Inside for loop 'a' increased by 1 and inside if block 'a' decrement by 1 until c reaches 7 i.e value of a is not changed.
Q156
8
Solution
Initially a=3,b=2.
Q157
2
Solution
Because the values of a1 and a2 are positive, it returns true for the given condition and set p=1 and p not equals 0 (true), So 2 gets
printed(1+1 is 2).
Q158
21 24 27 30
Solution
Because for loops run four times, the b value is added by three for each iteration.
Q159
6
Solution
If block and else if block condition gets failed, so else gets executed and prints c value(6).
Q160
0
Solution
The arithmetic operator has higher priority than the Logical operator.So 6 / 23 = 0 (0 && anything = 0).
Q161
3
Solution
Inside for loop a decrement by 1(a=2) and breaks out of the loop because d< 2( d value set as 0 by default).
Q162
17 15 4
Solution
When a=3 loop condition gets failed and prints a+1 (i.e) 4
Q163
test1 test completed
Solution
6 / 7 = 0 so k value set as 0.
k lessthan equal to 0 (Ture) so executes nested if condition (i.e) k equals to 0 (true) so test1 gets printed and last instruction prints "test
completed".
Q164
0
Solution
Q165
it will print biography 1 time
Solution
Initially n=15
while condition true so "biography" gets printed and n=15+2 => n=17.
n value greater than 15 so loop terminates.
Q166
11
Solution
combine(8) will call combine(16) and combine(16) will call combine(32),here 32>=17 so it return 32+3 = 35 to previous call. This process
repeat until it reaches first function call i.e combine(8). combine(8) returns 8+3 = 11.
Q167
44
Solution
The base condition returns double the value of the given value in this case. So 22 * 2 => 44.
Q168
99
Solution
f5(100) function called then it recursively call f5(99) , 99 % 2 =1 ,so it returns 99 (because it is pre-increment).
Q169
2
Solution
The value of the variable a is 2 and b is 7, the first if condition becomes true so it will enter inside the if condition and checks the second
condition if(b+1), it is true so it returns the value 2 from the function. Hence the output is 2.
Q170
Aptl
Solution
The characters in the even index will be printed. When an index is an odd number, space is printed.
Q171
56
Solution
Q172
1
Solution
While loop executes once and print p (1) value gets printed and breaks the loop.
Q173
80
Solution
Initially x=3.
Inside do-while loop x decremented to 2 , and printed 2*4 =8 and checks x not equal to 2 (False) so loop terminates.
2*(2/6)
=> 2*(0)
Q174
4
Solution
Initially a[4]={1,1,2,2}
a[0]=1+1 = 2 // {2,1,2,2}
a[1]=1+2 = 3 // {2,3,2,2}
a[2]=2+2 = 4 // {2,3,4,2}
a[3]=2+2 = 4 // {2,3,4,4}
m value set as last element in the array (m=4) and gets printed.
Q175
65
Solution
j value evaluated and set as 16. If block gets executed and set f as 10.
Q176
It is working
Solution
If blocks execute because k is a positive value and prints "it is working” once.
Q177
1
Solution
Q178
0
Solution
6 divided by 23 gives 0 (j=0).(0 && anyvalue =0) .So if block gets failed and 0*0 = 0 gets printed.
Q179
-3
Solution
For loop gets executed twice and increment the 'a' value (i.e) a= -1 when loops terminates.
Q180
1,1,1
Solution
When a user tries to assign more than one value to a variable, the first value is assigned to the variable.
Q181
67
Solution
Initially arr[3][2] = { { 12, 21},{13, 54},{ 52, 63} },x=1.
Outer for loop executes four times (i.e for 'k' values 0,1,2,3)
Because the loop accesses beyond the array size, the array value will be 0 for the next two iterations. So there is no changes in 'x' value
Q182
1
Solution
When you divide an integer by another integer, the outcome is also an integer.
Initially a=5, b= 8
Q183
when the value of a= 13
Solution
The program executes for all the odd numbers greater than 12, because the modulo of 2 result should not be equal to 0 (which means odd
values). Then 'a' should be greater than 12. So when the value of a= 13 option satisfies the above constrains.
Q184
1
Solution
Initially a= 3, b= 1
Inside for loop, 'a' value gets decremented for following d and c values.
(1, 1 ), (2 ,1), (2 ,2), (3 ,1), (3 ,2) (i.e) five times. So, a=3-5=> a= -2
Q185
you are promoted
Solution
Initially k= 2, p= 6
Q186
32
Solution
Initially a=11, b= 21. There are no changes in the variables because if block condition fails for all loop values.
Q187
6
Solution
5 && 2 =0 , 5 && 1 = 1
If block executed for all the values except 0. Here if condition expression result value is -1 (which is considered as true) and increments 'a'
value.
Q188
1
Solution
The logic of the program is to find a number of digits in the number. The total digit for the given number 128 is 3, so 'c' decrements three
times (4-3 = 1)
Q189
45
Solution
Inside loop all the array element are added twice and added again with 6 . Final result add with 1 (m value)
Q190
two times
Solution
Initially k= 1, p= 4
j= 4 + 0 = 4
Q191
hello
Solution
i value set as 57 (shown below) , so if block gets executed and prints "hello"
Q192
2
Solution
Initially a= 1, b= 2
Q193
6666
Solution
'd' value gets printed for below a,b and c values. (i.e) (a,b,c)
(1,1,1) , (1, 1, 2), (1, 2, 2), (2, 2,2) (totally 4 times 'd' value gets printed.
Q194
2
Solution
Initially a= 108, b= 2, c= 3
If block gets executed and update b value to 2 and b gets printed i.e 2.
Q195
9
Solution
In this recursive program, the recursive call is made until 'a' value becomes 0. fun(0) function call returns 9 and that value is passed to the
Q196
1
Solution
Initially i=45
45%2 = 1(True)
Q197
Functions fun finds the largest element of the linked list
Solution
While loop runs until pointer value becomes null (i.e) last value in the linked list.
When x is less than the current node value then update x with the current node value. Finally, x holds the maximum value in the linked list.
Q198
8
Solution
Initially str1= " momo" (length =4). For loop executes twice and append "mm" for each iteration.So 4+2+2 = 8.
Q199
it will print engineering 2 times
Solution
Initially a=10. 10 not equal to 5 (TURE) so the "engineering" string was printed and 'a' updated to 9. The else block is executed, and the
loop is exited.
Then a is 9 which is not equal to 2 , so again else block is executed and print "engineering". Totally two-time "engineering" gets printed.
Q200
10 times
Solution
(i.e) (0, 0), (1, 0) , (1, 1), (2, 0) , (2, 1), (2, 2), (3, 0), (3 ,1),(3, 2),(3, 3)
Q201
20
Solution
Solution
Q203
3579
Solution
i=2=> a[2/2] => a[1] = 2 => if block prints a[2*2] = 5. Similarly loop executes for i=3,4 and prints 7 and 9.
Q204
0
Solution
0=> 0000
1=> 0001
2=> 0010
3=> 001 1
---------------
^=> 0000
----------------
Q205
42 43 44 45
Solution
After that, the else block is executed, and the loop is exited.
Q206
Respect
Solution
In second while loop prints the "Respect" string which is stored in b array.
Q207
9 10 9 8
Solution
Initially k= 1, m= 9
Q208
It will print nothing
Solution
Initially s=78
While loop runs until s less than 89. After executing the continue statement, loop skips the below instruction and continue the next
Q209
18
Solution
Initially arr[]={10,7,2,6,1,2,3}
Q210
50
Solution
a= 20 +30 (1st and 2nd index value added and assigned to 'a')
Q211
2
Solution
Q212
0
Solution
Here is the math to illustrate how to get 20 mod 1 using our Modulo Method:
20 / 1 = 20
20 x 1 = 20
20 - 20 = 0
Q213
3
Solution
Q214
10
Solution
Q215
10 12 13 86 777
Solution
When fun(9) : 9>12 (false so else block executes), Inside else block 9 added with i value and gets printed as 10,12,13. Then backtracking
will happen to fun(86) and prints 86. Then again backtracking will happen to fun(777) and prints 777. So output is 10 12 13 86 777.
Q216
None of the mentioned options
Solution
When fun(0,6) => 0>1 (false) so print statement executes and print 6. Then function call backtrack to fun(2,4) and executes print
Then again function call backtrack to fun(4,2) and executes print statement and print 6. So output is 6 4 2.
Q217
5
Solution
When x=45 :
fun(45) => (45 % 6) % 2 = 1 (which is greater than 0) so function returns 45/9 => 5.
Q218
0
Solution
Q219
245
Solution
Iteration 2: x=229,y=16
Q220
31
Solution
Initially x = 11 , y = 10 then z and y updated with 3. l=1 because both x and z are non zero. So output is 3 1.
Q221
12 9 6 3
Solution
In fun(108,3) :
In fun(36,6) :
In fun(6,9) :
In fun(0,12) :
0>1 (false) so 12 gets printed and function call backtrack to fun(6,9) and prints 9. This process repeated until the function call backtrack
Q222
hat
Solution
String1= what
String2=e
String2 appended 4 times i.e whateeee. Then substring(1,4) => hat (from index 1 to 3)
Q223
62
Solution
Q224
5
Solution
Q225
17
Solution
Q226
tratStsart
Solution
Q227
12 24 36 48 60 61
Solution
Each time i value increments by 12 and gets printed. Once it reaches 60 it gets printed in line 4 and executes else block and increment by
Q228
38
Solution
When i=4 , q=0 and p=38. When i=5 loop terminates and prints 38.
Q229
72
Solution
r= 13%1=> 0
p=1+5=>6
q=6+0 =>6
r=6/5=>1
Q230
rrqrrqp
Solution
Initially a=pqr.
In fun(pqr) : len(pqr)>0 so fun(qr) called.
Then function call backtrack to fun(r) and again executes next line i.e. fun(r)
Then function call backtrack to fun(r) and prints r. The same process repeated and prints rrqrrqp.
Q231
14
Solution
Initially pp=7,qq=7,
Q232
25
Solution
Here the value of pp updated to 15,qq updated to 4 and rr=6 after performing the bitwise operations. So output is 15+4+6 => 25.
Q233
10
Solution
Initially pp=1,qq=5,rr=10
rr=(1&3)^1 => 0
Q234
1
Solution
Initially pp=1,qq=4,rr=8. Inside loop, all the times only if block gets executed and update the qq value
When rr=4,qq=0
When rr=5,qq=1
When rr=6,qq=0. Finally 1+0 => 1 gets printed.
Q235
23
Solution
For each iteration of m value gets updated. In the last iteration l=16(updated with max value in the array) and added with last value in the
Q236
traversing an array
Solution
Here k value moves from LB to UB and printing the array values. So it is just traversing the array.
Q237
It will print three If x=9, y=8, z=6
Solution
When x=9, y=8, z=6, first if condition is true but second if condition gets failed so line 7 else block executes and print three.
Q238
39 32
Solution
Initially b=7,c=1
When j=2,i=1,then c= 2
When j=2,i=2,then c= 4
When j=3,i=1,then c= 8
When j=3,i=2,then c= 16
When j=3,i=3,then c= 32
Finally loop terminates and print b=7+32=>39 and c=32. So 39 32 gets printed.
Q239
5
Solution
Q240
0
Solution
Inside for loop b value gets updated with 24+18=>42. Then after c=5 there wont be any changers in the b. After the termination of for loop
Q241
3
Solution
Initially q=81,r=10.
Q242
12 14 16 18 296
Solution
Initially a = 65,b= 0,c = 6,d= 0,i= 1. In while loop 65 > 6 (true), so b=12,d=12.Again it checks for 12<20 condition true. So b and d updated by
2 for each iterations until b> 20 by printing 12 14 16 18. These process repeated and at the end b= 296,d= 112 and c=66. So 296 gets
printed.
Q243
342
Solution
Q244
12 1
Solution
Inner while loop goes infinite loop because c value not get updated inside it.
Q245
100
Solution
Above pseudocode is used to find the max value in the array. So 100 gets printed.
Q246
4 18 31 43 23
Solution
Iteration 1:
Inner loop:
Iteration 2:
Inner loop:
Q247
12
Solution
Q248
13
Solution
Initially a=1
b=4
c=8
Q249
1
Solution
Q250
56
Solution
Initially p= 5, q = 5, r = 10
When r=8 if block condition gets true and break the loop. So 27+29=56.