Pseudocodes 2
Pseudocodes 2
• 5
• 6
• 4
What will be the outcome of the
following pseudo code for p=3 and q=4
int fun1(int p, int q)#3,4#f(6,2)#f(12,1)#f(24,0)
if(q EQUALS 0)
return 0
B. 7
C. 12
D. 8
• Option C
What will be the outcome of the
following pseudo code for a=2 and b=3
doSomething(Integer a, Integer b)
if(b EQUALS 1)
return 0
else
B. 4
C. 2
D. 1
• Option b
What will be the outcome of the
following pseudo code
Integer a, n, sum, q, r
Set q=a
n=n+1
q=q/10
End while
Print n
r=a mod 10
sum =sum + r
a =a/power(10, n- 1)
End while
Print sum
A. 3 2
B. 6 4
C. 6 5
D. 3 4
• Option D
What will be the outcome of the
following pseudo code
Integer a=5,b=8,c
if(a>8 OR b < 7)
c=a+b
c=a-b
else
a=a+5
c=c-2
end if
a=a+b
Print a and c
b=b-5
[Note: OR — The logical Or operator returns the Boolean value if either or both operands are true and returns false
otherwise.]
A. None of the mentioned
B. 5 -3
C. 5 1
D. 13 -3
• Option D
What will be the outcome of the
following pseudo code
Set Integer Emp_no=101
while(Emp_no=501)
salary=salary+100
Display salary
A. Code executes successfully and value of salary
is displayed once.
Do
- - res
Display res
res++
A. Code will run infinite number of times.
B. 1
C. 2
D. 8
• Option A
What will be the output of following
pseudocode
for i=0 to 4 step 1 do
if i==i++ + - -i then do
display i
end-if
end-for
A. 0
B. 3
C. 1
D. 2
• Option A
What will be the output of following
pseudocode
Set character c=‘7’
switch(c)
case ‘1’:display “One"
case ‘7’:display “Seven”
case ‘2’:display “Two”
default: display “Hello”
end-switch
A. SevenTwoHello
B. OneHello
C. SevenTwo
D. Seven
• Option A
What will be the output of following
pseudocode
Integer a,b,c
Set a=4,b=3,c=1
if (a>>(c-1)&&b<<(c+1))
a=a+c
else
b=a<<c
end if
print a-b+c
A. 3
B. 5
C. 8
D. None of these
• Option A
What will be the output of following
pseudocode
Integer a,p
Set a=5
a=a+1
a=a*2
a=a/2
p=a/5+6
print p
A. 0
B. 1
C. 2
D. 7
• Option D
What will be the output of following
pseudocode
Integer a,b,c
Set b=8,a=2
c=a^b
if(c^b)
b=0
End if
Print b
A. 3
B. 0
C. 10
D. 2
• Option B
What will be the output of following
pseudocode
Integer a,b,c
Set b=40,a=20,c=20
a=a+c
c=c+a
a=a+c
c=c+a
Print a+b+c
A. 40
B. 100
C. 300
D. None of these
• Option C
What will be the output of following
pseudocode
Integer a,b
Set a=1,b=1
a=(a^1)&1+(b^1)&1
Print a+b
A.1
B. 2
C. 0
D. None of these
• Option A
What will be the outcome of the
following pseudo code
• number=90
else
end-if
• Data within the range
• 12345
• 4 6 8 10
• 11 2 3 5
• Option a
What will be the output of the following
pseudocode if a=10 and b=6
• Integer func(integer a,integer b)
integer temp
while(b)
temp=a MOD b
a=b
b=temp
end-while
return a
end function func()
• 2
• 4
• 3
• 1
• Option a
What will be the outcome of the
following pseudo code
• Integer i, j, k
Set k = 8
for(each i from 1 to 1)
for(each j from the value of i to 1)
print k+1
end for
end for
• 2
• 6
• 9
• 5
• Option c
What will be the outcome of the
following pseudo code
• Integer i
Set i = 3
do
print i + 3
i=i-1
while(i not equals 0)
end while
A) 6 6 6
B) 6 5 6
C) 5 5 5
D) 6 5 4
• Option d
What will be the outcome of the
following pseudo code
• Integer a
String str1
a = stringLength(str1)
Print (a ^ 1)
A) 0
B) 4
C) 5
D) 3
• Option b
What will be the outcome of the
following pseudo code
• Integer a, b, c
Set a = 8, b = 51, c = 2
c = (a ^ c)^ (a)
b = b mod 4
Print a + b + c
A. 13
B. 17
C. 26
D. 16
• Option a
• Consider an array A = {1, 2, 4, 5, 6, 11, 12} anda
key which is equal to 10. How many
comparisons would be done to find the key
element in the array using the binary search?
A. 5
B. 1
C. 2
D. 3
• Option d
What will be the outcome of the
following pseudo code
• 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
A) 15
B) 7
C) 2
D) 0
• Option d
What will be the outcome of the
following pseudo code
• Integer arr[]={10, 20, 30, 40, 5}
Integer a, s
Set s = 0
Print a
A) 25
B) 5
C) 50
D) 40
• Option c
What will be the outcome of the
following pseudo code
• Integer a, b, c
Set b = 2, a = 2
c=a^b
Print c
A) 6
B) 4
C) 0
D) 2
• Option c
What will be the outcome of the
following pseudo code
• Integer x,y,z;
x=0
y=1
x=y=z=8
Print x
A) 0
B) 8
C) 1
D) None of the above
• Option b
What will be the outcome of the
following pseudo code
• Integer value, n
Set value = 1, n = 45
end loop
Print value
A) 64
B) 32
C) 45
D) None of the above
• Option a
What will be the outcome of the
following pseudo code
• Integer c, d
Set c = 15, d = 12
d = c – 1#14
Print c //line
c = d + (c – 2)
if(c < 40)
Goto line
end if
A) 14 26 38
B) 27 39
C) 15 27 39
D) None of the above
• Option c
Find the output of the following pseudo-
code if x= 4 and y=5:
• Integer fun(int x, int y)
if(x > 1)
fun(x – 2, y + 2)
end if
print y
x = x/y
z = y<<x
Print z
A) 1
B) 8
C) 0
D) 64
• Option d
What will be the outcome of the
following pseudo code
• Integer x, y, z, a
Set x = 2, y = 1, z = 5
a = (x AND y) OR (z + 1)
Print a
A) 5
B) 3
C) 2
D) 1
• Option d
What will be the outcome of the
following pseudo code
• Integer a=5, b=4, c=3
a=b+c
c=a–b
c=c+a
c=b+c
b=b+c
Print a, b, c
A) 7 14 7
B) 7 14 10
C) 7 8 14
D) 7 18 14
• Option d
What will be the output of the following pseudocode if n=5 and
elements of array are 24,20,60,100,200?
Integer fun(Integer a[], Integer n)
Integer x
if(n is equal to 1)
Return a[0]
else
x=fun(a,n-1)
If(x<a[n-1])
Return x
Else
Return a[n-1]
End Function fun()
• 60
• 20
• 24
• 100
What will be the output for the following pseudocode for
input pqr?
Fun(char a)
if(a[0] equals NULL)
return
end if
fun(a+1)
fun(a+1)
print(a[0])
End function Fun
• None of the mentioned
• rqppqr
• rrqrrqp
• ppqqrr
What will be the outcome of the
following pseudo code
• Integer a, b, c, d
Set b = 18, c = 12
a=b–c
for (each c from 1 to a – 1)
b = b + c + 12
b = b/5
d=b+a
end for
c=a+b+c
Print a b c
A) 539
B) 6 14 17
C) 6 4 14
D) 6 4 16
• Option d
What will be the outcome of the
following pseudo code
• Input m = 9, n = 6 ,
m=m+1;
n=n-1;
m=m+n
if (m > n)
print m
else
print n
A) 6
B) 5
C) 10
D) 15
• Option d
What will be the outcome of the
following pseudo code
• For input a = 8 & b = 9.
function (input a, input b)
If (a < b)
return function (b, a)
elseif (b != 0)
return (a + function (a, b - 1))
else
return 0
A) 56
B) 88
C) 72
D) 65
• Option c
What will be the outcome of the
following pseudo code
Input f = 6, g = 9 and set sum = 0
Integer n
if (g > f)
for (n = f; n < g; n = n + 1)
sum = sum + n
End for loop
else
print error message
print sum
A) 21
B) 15
C) 9
D) 6
• Option a
• Option c
def add1(n2):
if n2!=0:
return (n2+2)+add1(n2-1)
else:
return 3
def add(n1):
if n1!=0:
return add1(n1)+add(n1-1)
else:
return 0
print(add(5))
• 25
• 52
• 70
• 80
• Option d 28,21,15,10,6
What will be the output of the following pseudocode if
x=4?
integer i
i = 64 / square ( x )
print i
• 64
• Garbage value
• 4
• 16
What will be the output of the following pseudocode if
a=3?
print square(a+2)
• 11
What will be the output of the following pseudocode?
print *a + 1 - * a + 3
• 4
• 100
• 44
• error
what will be the output of the following pseudocode?
Integer a, b, c
Set b = 1, c= 1
For(each a from 1 to 3)
b = b >> 1
c = c << b
End for
Print b + c
A. 1
B. 0
C. None
D. 2
#define PRODUCT(x) (x*x*x*x)
int x = 2;
• 3 81
• 6 120
• 6 1296
Predict the output of the given pseudo code
if the value of n is 26 :
Read n
i=0
While n % 8 != 0
n=n+5
i++
end while
n=n+i
print n
• 16
• 32
• 10
• 62
• Option d
Predict the output of the given pseudo code
if the value of n is 35 :
Read n
i=0
While n % 10 != 0
n=n+3
i++
end while
n = n+i
print n
• 55
• 45
• 50
• 43
• Option a
Predict the output of the following
pseudocode
Integer x, y
Set x = 10, y = 8
Print ((x | 1) & (4) + (y ^ 1) & (1))
• 1
• 3
• 2
• 0
• Option a
What will be the output of the following
pseudocode?
Set x = 'a' * 10;
print x
• 97
• 970
• 10
• 200
• Option b
Predict the output of the given pseudocode
Set n = 14, sum = 0, i = 5
while i < n do
increase sum by 2 * i
increment i
end while
Write sum
• 117
• 130
• 162
• 140
• Option c
Predict how many times the value of res will
be displayed.
Set Integer res = 0
do
++res
display res
while(res <= 5)
End do-while
• The program will not enter the loop.
• initialize char c
• set c= a
• print "%d",a
A) 64
B) 97
C) a
D) error
• Option b
What will be the output of the following
pseudo code for arr[]= 1,2,3,4,5
• initialize i,n
for 0 to n -1
arr[i] = arr[i]+arr[i+1]
end for
print arrayword[loopcounter]
a=1
b=3
c=(a++,b,a)
print c
A) 1
B) 2
C) 3
D) 4
• Option b
What will be the output?
• Integer x,y,z,a
set y=2
set x=(y=y*2)+(z=a=y)
print x
A) 8
B) 4
C) 2
D) 1
• Option a
What will be the output?
• Integer x=5
set b1=true
set b2=false
if((x==4)&&!b2)
print 1
print 2
if ((b2=true)&&b1)
print 3
A) 23
B) 12
C) 13
D) 2
• Option a
What will be the output?
• Integer x=0,y=20
while(x<10)
y=y-1
x=x+1
end while
print x and y
A) 20 10
B) 20 20
C) 10 10
D) 10 20
• Option c
What will be the output?
• Integer a[4]={4}
Integer i
for(each i from 0 to 2)
print a[i]
A) 004
B) 040
C) 400
D) 123
• Option c
What will be the output?
• Integer x=10
Integer y=15
if (!(!x)&&x)
print x
else
print y
A) 15
B) 10
C) 1
D) 0
• Option b
What will be the output?
• Integer a=10
if (!(!a)&&!a)
print !!a
else
print !a
A) 0
B) 10
C) 1
D) none
• Option a
What will be the output?
• Integer n
for(n=3;n!=0;n- -)
print n
n=n-1
end for
A) 31
B) 321
C) 3
D) infinite loop
• Option d
How many times loop will be executed?
• Ch=b;
while(ch>=a&&ch<=z)
ch++
A) 0
B) 25
C) 26
D) 1
• Option b
What is output?
• Integer x=5,y=10,z=15,a
a=x<y<z
print a
A) 0
B) 5
C) 10
D) 1
• Option d
What is output?
Integer a[5]={5,1,15,20,25}
Integer i,j,m
I=++a[1]
j=a[1]++
m=a[i++]
print i,j,m
A.2,1,5
B.1,2,5
C.3,2,15
D.2,3,20
• Option c
What is output?
integer n=1234
integer q,r,rn
set q=n and rn=0
while(q>0)
r=q mod 10
rn=rn+r^3(^ for power)
q=q/10
end while loop print rn
A.100
B.36
C.321
D.10
• Option a
What is output?
Integer x,y,z
x=y=z=1
z=++x||++y&&++z
print x y z
A.2 1 1
B.2 2 1
C.2 2 2
D.1 2 1
• Option a
What is output?
Integer a=10,x
x=a-- + ++a
print x
A.19
B.20
C.21
D.23
• Option b
How many times does the below for loop
repeated?
for (i=5;i>=1;i--)
for(j=1;j<=i;j++)
print y
A.15
B.11
C.10
D.13
• Option a
What will be the output of the given pseudocode?
Integer a,b,c
Set a=5,b=3,c=6
b=(c&b)+b
for (each c from 2 to 4)
b=(5&6)^a
End for
print a+b
Select the appropriate answer from the given choices
24.0
11.0
-12.0
6.0
6.0
What will be the output of the given pseudocode?
Integer a,b,c
Set a=5,b=7,c=5
b=(1^4)+b
if((c&b&a)<(a&c))
c=a+a
End if
print a+b+c
27
What will be the output of the given pseudocode for
a=2,b=7 and c=6
1.Integer funn (Integer a, Integer b, Integer c)
2 b=(c^8)+c
3 for(each c from 4 to 7)
4 b=(c+11)&b
5 a=11&a
6 End for
7 return a+b
2
What will be the output of the following pseudocode for
a=0,b=4,c=6?
Integer funn(Integer a,Integer b,Integer c)
a=c^a
if (c^a^b)<(a+b+c)
b=(2+5)&a
b=(b&8)^b
end if
a=6^a
return a+b+c
12
17
15
9
A
What will be the output of the following
pseudocode for i=140?
Integer fun(int i)
if i%2!=0
return i
else
return fun(fun(i=1))
End function fun()
1
Error
A
What will be the output of the given pseudocode
for a=3, b=9
Integer funn(Integer a,Integer b)
if ((b-a)>(a&b) &&(b^a)>(6-b))
a=1+2+a
a=1+3+b
b=a+3
return funn(b,b)+b
end if
return a-1
40
37
31
28
C
What will be the output of the given pseudocode
for a=8,b=2?
Integer funn(Integer a,Integer b)
if b<a && 4>b
b=1+1+a
a=2+1+b
return funn(a,b)
end if
b=b+2+b
return a+b
43
35
38
31
B
What will be the output of the given pseudocode
for a=6,b=7?
Integer funn(Integer a,Integer b)
if b>a && a>3
a=b+1+a
b=1+3+a
return a-funn(b,b)
end if
return b-1
-16
-3
14
C
What will be the output of the given pseudocode for
a=8,b=7,c=4?
Integer funn(Integer a,Integer b)
a=b+b&c
b=3+c
b=4+7+b
a=(b&c)+c
end for
c=a+c
return a+b
37
23
16
33
D
What will be the output of the given pseudocode
for a=7,b=8?
Integer funn(Integer a,Integer b)
if (b&a)>(a-b) && a>4
a=3+b+b
a=2+b+a
return a-funn(a,b)+funn(a+1,b)
end if
a=a+1
return a-1
30
29
31
28
A
What will be the output of the given pseudocode
for a=1,b=1?
Integer funn(Integer a,Integer b)
if a<3 && (a&b)<(b+a)
b=a+2
b=b+1
return b-funn(b,b)
end if
b=b+3
return a+b
-12
-7
-2
-5
B
Keep the statement language ______________ while
writing a pseudo code.
• Dependent
• Independent
• Case sensitive
• capitalized
• Option b
Capitalize initial keyword – This is a rule while writing a
pseudo code.
• True
• False
• true
Which of the following is not a keyword?
• read
• Write
• Start
• End if
• Option c
______________ is used to show hierarchy in a
pseudo code.
• indentation
• Curly braces
• Semicolon
• Round braces
• Option a
The statement that tells the computer to get a value from
an input device and store it in a memory location.
• read
• write
• READ
• WRITE
• Option c
_____________ are identified by their addresses, we give
them names (field names / variable names) using words.
• Memory variables
• Memory locations
• Memory addresses
• Data variables
• Option b
• ____________ begins with lower case letters.
• Keywords
• Variables
• Tokens
• Functions
• Option b
• Another notation for exponentiation.
• *
• **
• ***
• *^
• Option b
• A symbol used for grouping.
• ()
• {}
• []
• ““
• Option a
• A statement used to close the IF block.
• ELSE
• ELSEIF
• END
• ENDIF
• Option d
• What does the following piece of code do?
• public void func (Tree root)
{
func (root.left ());
func (root.right ());
System.out.println (root.data ());
}
• Predorder traversal
• Postorder traversal
• Inorder traversal
Integer a
Switch(a=b+1)
break
End switch
• Infinite loop
• Error
• Pseudo
• Pseudocode
• Option d
• What will be the output of the following pseudocode?
If x equals y then
else
End if
• They are unequal
• Not answered
• error
• Option c
• How many iterations will the following pseudocode make
to find key with value 37?
Integer key
Set Integer array=[27,17,47,37,67]
for ele=0 to 4 step 1 do
if array[ele] equals key
display “found”
end-if
End for
• 5
• 3
• error
• 4
• Option d
• What will be the output of the following
pseudocode?
display result
• 9
• 10
• 18
• 19
• Option b
• What will be the output of the following
pseudocode?
• 4
• 0
• 1
• Option d
• What will be the output of the following pseudocode if
n=10?
Read n
Initialize i to 5//i=5
While i<n, do://5<10-t
increase sum by i//sum=sum+i//0+5=5
increment i//6
End while
Write sum
• 35.0
• 25.0
• 45.0
• 55.0
• Option a
• Problem statement: find the closest pair of points in
an array of distinct points
• Assume that you solve this problem by comparing all
pairs of points. What will be the complexity of this
approach?
• O(n*2)
• O(n)
• O(n log n)
• Cannot be determined
• Option a