TCS NQT - cap ability

Test Number 1/11

Q: What will be the output of the following pseudo code for a=50?

Integer fun( Integer a)
Integer b
Set b = 10
Return a-b
End function fun()
A. 50
B. 40
C. 60
D. none
Solution: 40
Q: What will be the output of the following pseudo code ?

Integer x, y, z
Set x=0, y=1
For( each z from 0 to 2 )
x = x + y + z
End for
print x
A. 5
B. 6
C. 7
D. 8
Solution: 6
Q: What will be the output of the following pseudo code ?
( Note : mod finds the remainder after division of one number by another. ^ is the bitwise XOR operator here )

Integer i, j, k, m
Set j = 6, i = 8, k = 7, m = 1
If (( i^j ) mod k EQUALS 0 )
m = m + 1
else
m = m - 1
End If
Print m
A. 3
B. 0
C. 1
D. 2
Solution: 2
Q: What will be the output of the following pseudo code for input 134 ?

Integer fun( Integer num )
Static Integer a = 0
If (num > 0)
a = a + 1
fun ( num /10 )
Else
Return a
End Function
A. 8
B. 2
C. 3
D. 431
Solution: 3
Q: What will be the output of the following pseudo code?

Integer j, m
Set m = 2
Integer a[4] = { 2, 4, 2, 2 }
If ( a[1] > 3 )
a [1] = a [2]
End If
If (1)
a [2] = a [1] + 2
End If
m = m + a[3] + a[2]
Print m
A. 2
B. 8
C. 1
D. 7
Solution: 8
Q: What will be the output of the following pseudo code?

Integer a, b, c
Set a = 5, b = 3
For ( each c from b to a )
If ( a )
a = a -1
End if
If ( b )
b = b -1
End if
End for
Print a + b
A. 8
B. 4
C. 6
D. 7
Solution: 4

You Have Score    /6