Mettl - Accenture - Pseudocode WA

Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

Pseudocodes - Accenture

Consider a program that prints Fibonacci series. The program


takes the number of elements in the series as input from the user.
Which of the following pseudocodes will print the series as required?

b c d

a Answer: a
What will be the content of the stack A)1
after execution of the following code? B) 1.7
C) 7
D)1.6.7

Answer: A
Which of the following is correct pseudocode
Using case statement for the given statement?

a b

c d

Answer: d
Which of the following is the pseudocode for taking
three numbers as input and printing the biggest number? Answer: B

A B C D
How many times the while loop will be executed for N= 8?

A. 4 B. 8
C. 5 D. 9 Answer: C
Provide sample pseudocode for performing an
operation, multiple times, but declared only Once.
A function routine is needed for calculator purpose.

B
A

C D Answer: A
What structure does the following pseudo code belong to?

A. decision
B. sequence
C. nested
D. loop
Answer: C
What will be the output of the following code?

A. 26 B. 5
C. 7 D. 21
Answer: B
What will be the output of the following code?

A. 41
B. 45
C. 37
D. 55

Answer: A
What will be the output of the following code?
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 OR operator that compares each bit of
its first operand 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 to 0.

A. 28
B. 3
C. 21
D. 12
Answer: D
What will be the output of the following code?
What will be the output of the following code?
Note: Continue: When a continue statement
is encountered inside a loop, control jumps to
the beginning of the loop for next iteration,
skipping the execution of statements inside
the body of the loop for the current iteration.

A. 14
B. 7
C. 19
D. 25
Answer: A
What will be the output of the following code?
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 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 bit is 0,
and the other bit is 1, the corresponding result bit is set to 1.
Otherwise, the corresponding result bit is set to 0.

A. 29
B. 20
C. 15
D. 12 Answer: C
What will be the output of the following code?
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 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
bit is 0, and the other bit is 1, the corresponding
result bit is set to 1. Otherwise, the
corresponding result bit is set to 0.

A. 46
B. 41
C. 25
D. 34 Answer: D
What will be the output of the following code
for a=1, b=3, c=4?
Note: ^ is the bitwise exclusive OR
operator that compares each bit of
its first operand 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 to 0.

A. 36 B. 17
C. 26 D. 22 Answer: D
What will be the output of the following code
for a=5, b=5, c=5?

A. 14
B. 27
C. 22
D. 15

Note- &&: logical AND - The logical AND operator (&&) returns the Boolean value true (or 1) if both operands are
true and return false (or 0) otherwise. & 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 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 bit is 0, and the other bit is 1, the
corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. Answer: D
What will be the output of the following code?
Note- &&: logical AND - The logical AND operator (&&)
returns the Boolean value true (or 1) if both operands are
true and return false (or 0) otherwise. ^ is the bitwise
exclusive OR operator that compares each bit of its first
operand 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
to 0.

A. 18
B. 20
C. 23
D. 30
Answer: B
Consider the following pseudocode:

A. a. The program prints the numbers which will be


found in the middle when the three numbers are sorted.
b. The output will be ‘The result is 10’
B. a. The program prints the largest among the three numbers
input
b. The output will be ‘The result is 20’
C. a. The program prints the second smallest among the three
numbers input
b. The output will be ‘The result is 10’
D. a. The program prints the smallest among the three
numbers input
b. The output will be ‘The result is 5’

a) What is the result that the program is trying to


output in this code when three numbers are input?
b) What will be printed when the input given to the program is 10,20,5? Answer: B
In any application like Ola, up to a certain kilometre, a fare is
calculated. After that, for each kilometre, the additional fare is
calculated. Choose an option that contains a sample snippet of code.

A B

C D

Answer: D
What will be the output of the following code?

A. 23
B. 41
C. 48
D. 58
Answer: B
What will be the output of the following code
for a = 0, b = 2, c =10 ?

A. 59
B. 68
C. 70
D. 39

Answer: A
What will be the output of the following code?
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 OR operator that compares each
bit of its first operand 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 to 0.

A. 29 B. 18
C. 10 D. 16 Answer: D
What will be the output of the following code?
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 OR operator that compares each bit
of its first operand 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 to 0.

A. 20 B. 27
C. 25 D. 36 Answer: C
What will be the output of the following code?
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.

A. 35
B. 49
C. 19
D. 28 Answer: D
What will be the output of the following code?

A. 17
B. 10
C. 23
D. 13

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. II. Logical OR - The logical OR operator (II) returns the Boolean value
TRUE(or 1) if either or both operands is TRUE and FALSE(or 0) otherwise
Answer: D
What will be the output of the following code
for a=1, b=2, c=9?

A. 26
B. 55
C. 40
D. 44

Note- ^ is the bitwise OR operator that compares each bit of the first operand to the
corresponding bit of the 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 to 0.
Answer: C
What will be the output of the following code
for a=2, b=6, c=5? Answer: B
A. 33
B. 32
C. 41
D. 28

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.
What will be the output of the following code?
Note-&&: Logical AND - The logical AND operator (&&)
returns the Boolean value true(or 1) if both operands are true
and return false (or 0) otherwise. &: 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 operand 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 to 0.

A. 45 B. 36
C. 31 D. 38 Answer: B
What will be the output of the following code?

Answer: D
A. 34
B. 20
C. 32
D. 25

Note-&&: Logical AND - The logical AND operator (&&) returns the Boolean value true(or 1) if both operands
are true and return false (or 0) otherwise. &: 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.
What will be the output of the following code?

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 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 bit is 0 and the other bit is 1, the corresponding
result bit is set to 1. Otherwise, the corresponding result
bit is set to 0.

A. 10 B. 13
Answer: C
C. 12 D. 19
What will be the output of the following code?

A. 22
B. 32
C. 27
D. 45

Answer: C
What will be the output of the following code?

A. 58 B. 34
Answer: C
C. 45 D. 49
What will be the output of the following code?

A. 5
B. 1
C. 9
D. 20

Answer: A
What will be the output of the following code
for a=6, b=8, c=4?
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 operand 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 to 0.
A. 11 B. 5 C. 27 D. 8 Answer: D
What will be the output of the following code
for a=3, b=4, c=4? Note- &&: Logical AND - The logical
AND operator (&&) returns the Boolean
value true(or 1) if both operands are true
and return false (or 0) otherwise.
&: 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 operand to the corresponding bit of
its second operand. If one bit is 0 and
the other bit is 1, the corresponding
A. 51 B. 53 C. 56 D. 47 result bit is set to 1. Otherwise, the
corresponding result bit is set to 0.
Answer: A
What will be the output of the following code
for a=1, b=6, c=5 ?
Note- ^ is the bitwise exclusive
OR operator that compares each
bit of its first operand 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
to 0.

A. 269 B. 279 C. 266 D. 262 Answer: C


What will be the output of the following code?

A. 15, 4
B. 7
C. 11, 4
D. none

Answer: B
What will be the output of the following code?
Note- Continue: When a continue statement is encountered
inside a loop, control jumps to the beginning of the loop for
next iteration, skipping the execution of statements inside
the body of the loop for the current iteration. ^ is the bitwise
OR operator that compares each bit of its first operand 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 to 0. If(x) gets
executed if the value inside if(), i.e., x is not zero]

A. 8 B. 9 C. 10 D. 11

Answer: A
What will be the output of the following code?

Note: If(x) gets executed if the


value inside if (), i.e. x is not zero

A. 7 B. 9 C. 2 D. 6 Answer: D
What will be the output of the following code
for a=4, b=6 ?
Answer: A

A. 21
B. 33
C. 19
D. 22

[Note>> bitwise right shift operator, it takes two numbers, right shifts the bits of the first operand, the
second operand decides the number of places to shift. << is left shift operator, it takes two numbers,
left shifts the bits of the first operand, the second operand decides the number of places to shift]
What will be the output of the following code
for a=3, b=0 ?
[Note: if(x) gets executed
if the value inside if(),
i.e., x is not zero]

A. 4 B. 14 C. - 18 D. 1

Answer: D
What will be the output of the following code?
[Note - >>-Bitwise right shift operator, it takes two
numbers, right shifts the bits of the first operand, the
second operand decides the number of places to shift.
&: bitwise AND - The bitwise AND operator (&) compares
each bit of the first operand to the corresponding bit of the
second operand. If both bits are1, 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 bit is 0 and the other bit is
1, the corresponding result bit is set to 1. Otherwise, the
corresponding bit is set to 0.

A. 13 B. 0 C. 20 D. 45 Answer: C
What will be the output of the following code? Answer: C

[Note: MOD finds the remainder 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 remainder of 1. & - Bitwise AND operator, it
takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits
are 1. ^ - is the bitwise exclusive OR operator that compares each bit of its first operand 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 to 0]
A. 13 B. 0 C. 23 D. 56
What will be the output of the following code?

Answer: A
A. 7 B. 5 C. 4 D. none
What will be the output of the following code?
[Note: || : 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]

A. 37
B. 18
C. 31
D. 32

Answer: B
What will be the output of the following code?

[Note- Continue: When a continue statement is


encountered inside a loop, control jumps to the
beginning of the loop for next iteration, skipping the
execution of statements inside the body of the loop for
the current iteration. ||: 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]

A. 23
B. 45
C. 56
D. 21
Answer: D
What will be the output of the following code
for a=5, b=4 ?

A. 20 B. 23
C. 28 D. 42 Answer: B
What will be the output of the following code
for a=2, b=5 ?

A. 7 B. 15
C. 5 D. 8 Answer: A
What will be the output of the following code
for a=99, b=2 ?

A. 2 B. 8
C. 6 D. 3

Answer: A
What will be the output of the following code Answer: B
for a=4, b=9 ?

A. 2
B. 8
C. 6
D. 3

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. If(x) gets executed if the value inside if(), i.e., x is not
zero]
What will be the output of the following code?

A. 246
B. 0246
C. 6420
D. 666

Answer: D
What will be the output of the following code?
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 o.
^ is the bitwise exclusive OR operator that
compares each bit of its first operand to the
corresponding bit of its second operand. If
one bit is o and other bit is 1, the
corresponding result bit is set to 1. Otherwise,
the corresponding result bit is set to 0
II: Logical OR - The logical OR Operator (II)
returns the boolean value TRUE(or 1) if either or
both operands is TRUE and returns FALSE(or 0)
otherwise]

A. 10 B. 45 C. 5 D. 7 Answer: C
What will be the output of the following code?
Note- &&:Logical AND - The logical AND
operator (&&) returns the Boolean value
true(or 1) if both operands are true and return
false {or 0) otherwise &: 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 exculsive OR operator
that compares each bit of its first operand 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
to 0 If(x) gets executed if the value inside if(),
A. 4 B. 5 C. 6 D. 7
i.e., x is not zero] Answer: C
What will be the output of the following code? Answer: C

A. 1
B. 2
C. 3
D. 4

Note-&: bitwise AND operator (&) compares each bit of the first operand to the corresponding bit of the
second operand. If both bits are 1, 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 bit is 0 and the other bit is 1, the corresponding result bit is
set to 1. Otherwise, the corresponding result bit is set to 0. If(x) gets executed if the value inside if(), i.e., x is
not zero.]

You might also like