Psuedocode Infosys 100
Psuedocode Infosys 100
and q = 4?
int fun1(int p, int q)
if(q EQUALS 0)
return 0
if(q mod 2 EQUALS 0)
return fun1(p + p, q/2)
return fun1(p + p, q/2) + p
End function fun1()
A. None of the options
B. 7
C. 12
D. 8
Answer: C
Explanation: The function is recursive. Initially, p = 3 and q = 4. The
process will double p and halve q until q becomes 0. Finally, it returns
12.
Q53) What will be the output for the following pseudocode with
a = 6 and b = 3?
Function calc(Integer a, Integer b)
if(b == 0)
return 1
else
return a * calc(a, b - 1)
End if
End function
Print calc(a, b)
A. 6
B. 18
C. 216
D. 729
Answer: C
Explanation:
Recursive function calculates a^b. Here, 6^3 = 216.
Q54) What is the output for the following pseudocode if x = 7
and y = 2?
Function mystery(Integer x, Integer y)
if(y == 0)
return x
else
return mystery(x + y, y - 1)
End if
End function
Print mystery(x, y)
A. 7
B. 10
C. 12
D. 15
Answer: B
Explanation:
Call stack: mystery(7, 2) -> mystery(9, 1) -> mystery(10, 0)..
1: 1 -> 1 bit.
2: 10 -> 1 bit.
3: 11 -> 2 bits.
4: 100 -> 1 bit.
Total = 5 bits.
Print gcd(a, b)
A. 1
B. 4
C. 2
D. 9
Answer: A
Explanation:
The pseudocode implements the Euclidean algorithm for finding
GCD.
gcd(9, 4) -> gcd(4, 1) -> gcd(1, 0).
Q58) What will be the result for the pseudocode below for a =
10, b = 2?
Integer a, b, count
Set count = 0
while(a > 0)
if(a mod b == 0)
count = count + 1
a=a-1
End while
Print count
A. 4
B. 5
C. 10
D. 2
Answer: B
Explanation:
The pseudocode counts numbers divisible by b from 1 to a.
Divisible: 2, 4, 6, 8, 10. Count = 5.
Q59) What will be the output of the following pseudocode for n
= 4?
Function computeSum(Integer n)
if(n == 0)
return 0
else
return n + computeSum(n - 1)
End if
End function
Print computeSum(n)
A. 10
B. 6
C. 15
D. 4
Answer: A
Explanation: The pseudocode calculates the sum of the first n
natural numbers.
For n = 4, sum = 4 + 3 + 2 + 1 = 10.
Print mystery(a, b)
A. 12
B. 81
C. 64
D. 243
Answer: B
Explanation:
The pseudocode computes a^b.
For a = 3 and b = 4, result = 3^4 = 81.
Print calcGCD(x, y)
A. 1
B. 2
C. 3
D. 5
Answer: A
Explanation:
The pseudocode implements the Euclidean algorithm.
calcGCD(5, 3) → calcGCD(3, 2) → calcGCD(2, 1) → calcGCD(1,
0).
Final result: 1.
reverseArray(arr, length(arr))
A. 4 3 2 1
B. 1 2 3 4
C. 4
D. None
Answer: A
Explanation:
The pseudocode prints the array in reverse order using recursion.
Print factorial(n)
A. 3
B. 6
C. 9
D. 1
Answer: B
Explanation:
The pseudocode calculates n!.
For n = 3, result = 3 * 2 * 1 = 6.
Print isEven(n)
A. true
B. false
C. Error
D. None
Answer: A
Explanation:
The pseudocode checks if a number is even recursively.
For n = 6, result = true.
Print mystery(a, b)
A. 15
B. 8
C. 5
D. 3
Answer: A
Explanation:
The pseudocode calculates the product of two numbers using
recursion.
For a = 5 and b = 3, result = 5 * 3 = 15.
Print countDigits(x)
A. 4
B. 5
C. 3
D. None
Answer: A
Explanation:
The pseudocode counts the number of digits in x using recursion.
For x = 1234, result = 4.
Print reverse(n, 0)
A. 4321
B. 1234
C. 2143
D. 0
Answer: A
Explanation:
The pseudocode reverses the digits of n recursively.
For n = 1234, result = 4321.
Q76) What will be the output of the following pseudocode for n
= 4?
Function factorial(Integer n)
if(n == 0)
return 1
else
return n * factorial(n - 1)
End if
End function
Print factorial(n)
A. 16
B. 24
C. 8
D. None
Answer: B
Explanation:
The pseudocode calculates n! recursively.
For n = 4, result = 4 * 3 * 2 * 1 = 24.
Q77) What is the output of the pseudocode for arr = [4, 6, 8]?
Function maxArray(Array arr, Integer n, Integer maxVal)
if(n == 0)
return maxVal
else
return maxArray(arr, n - 1, max(arr[n - 1], maxVal))
End if
End function
Print sumDigits(a)
A. 12
B. 3
C. 6
D. None
Answer: B
Explanation:
The pseudocode calculates the sum of digits of a recursively.
For a = 12, result = 1 + 2 = 3.
Print evenSum(n)
A. 12
B. 20
C. 18
D. 6
Answer: A
Explanation:
The pseudocode calculates the sum of even numbers up to n.
For n = 6, result = 6 + 4 + 2 = 12.
printNumbers(n)
A. 5 4 3 2 1
B. 1 2 3 4 5
C. Error
D. None
Answer: A
Explanation:
The pseudocode prints numbers from n to 1 recursively.
For n = 5, result = 5 4 3 2 1.
Print isPrime(n, n - 1)
A. True
B. False
C. Error
D. None
Answer: A
Explanation:
The pseudocode checks if n is prime recursively.
For n = 7, no divisor exists between 7 and 1. Output = True.
Q84) What is the output for the array arr = [1, 2, 3, 4, 5] in the
pseudocode?
Function sumArray(Array arr, Integer n)
if(n == 0)
return 0
else
return arr[n - 1] + sumArray(arr, n - 1)
End if
End function
Print fibonacci(n)
A. 5
B. 3
C. 2
D. 8
Answer: B
Explanation:
For n = 4, the Fibonacci sequence follows this recursive pattern:
fibonacci(4) = fibonacci(3) + fibonacci(2)
o fibonacci(3) = fibonacci(2) + fibonacci(1)
fibonacci(2) = fibonacci(1) + fibonacci(0)
fibonacci(1) = 1 (base case)
fibonacci(0) = 0 (base case)
fibonacci(2) = 1 + 0 = 1
fibonacci(1) = 1
fibonacci(3) = 1 + 1 = 2
o fibonacci(2) = 1
o fibonacci(4) = 2 + 1 = 3
Thus, the final output for fibonacci(4) is 3.
Print power(x, y)
A. 6
B. 8
C. 9
D. None
Answer: C
Explanation:
The pseudocode calculates x^y recursively.
For x = 3, y = 2, result = 3 * 3 = 9.
printPattern(x)
A. 4 3 2 1
B. 4 3 2 1 1 2 3 4
C. 4 3 2 1 2 3 4
D. None
Answer: C
Explanation:
The pseudocode prints a pattern recursively.
For x = 4, result = 4 3 2 1 2 3 4.
Print factorialSum(a)
A. 125
B. 130
C. 150
D. None
Answer: D
Q89) What will the pseudocode return for arr = [2, 4, 6]?
Function evenProduct(Array arr, Integer n)
if(n == 0)
return 1
else
return arr[n - 1] * evenProduct(arr, n - 1)
End if
End function
Print seriesSum(n)
A. 9
B. 15
C. 8
D. None
Answer: A
Explanation:
The pseudocode calculates the sum of numbers skipping by 2.
For n = 5, result = 5 + 3 + 1 = 9.
Print sumEvenNumbers(n)
A. 12
B. 20
C. 18
D. 6
Answer: A
Explanation:
The pseudocode sums all even numbers up to n.
For n = 6, result = 6 + 4 + 2 = 12.
Q92) What is the output for the following pseudocode if arr = [1,
2, 3, 4, 5]?
Function maxValue(Array arr, Integer n)
if(n == 1)
return arr[0]
else
return max(arr[n - 1], maxValue(arr, n - 1))
End if
End function
Print gcd(x, y)
A. 1
B. 2
C. 3
D. None
Answer: A
Explanation:
The pseudocode calculates the greatest common divisor (GCD).
For x = 3, y = 2, result = 1.
Print countDigits(n)
A. 4
B. 3
C. 1
D. None
Answer: C
Explanation:
The pseudocode counts the number of digits in n.
For n = 4, result = 1 (single digit).
Q95) What is the output for this pseudocode for arr = [2, 3, 5, 7]?
Function sumPrimes(Array arr, Integer n)
if(n == 0)
return 0
else if(isPrime(arr[n - 1]))
return arr[n - 1] + sumPrimes(arr, n - 1)
else
return sumPrimes(arr, n - 1)
End if
End function
Print factorialDifference(n)
A. 1
B. 4
C. 7
D. 6
Answer: B
Explanation:
The pseudocode alternates subtracting the factorial difference.
Print reverseBinary(x)
A. 1000
B. 1
C. 0001
D. 111
Answer: A
Explanation:
The pseudocode calculates the reverse binary of x.
For x = 8, binary = 1000. Reverse remains 1000.
Q98) What will be the output for the following pseudocode with
n = 4?
Function calculate(Integer n)
if(n == 1)
return 1
else
return n * calculate(n - 1) + n
End if
End function
Print calculate(n)
A. 64
B. 24
C. 20
D. 22
Answer: A
Explanation:
This pseudocode calculates a modified factorial with an addition at
each step.
Q99) What is the output of the following pseudocode for n = 5?
Function mysterySum(Integer n)
if(n == 0)
return 0
else
return n + mysterySum(n - 2)
End if
End function
Print mysterySum(n)
A. 9
B. 12
C. 6
D. 15
Answer: A
Explanation:
This pseudocode adds alternate integers.
For n = 5, result = 5 + 3 + 1 = 9.
Q100) What will the following pseudocode output for arr = [10,
20, 30, 40, 50]?
Function rotateLeft(Array arr, Integer n)
if(n == 1)
return arr
else
temp = arr[0]
for i = 0 to length(arr) - 2
arr[i] = arr[i + 1]
End for
arr[length(arr) - 1] = temp
return rotateLeft(arr, n - 1)
End if
End function
Print rotateLeft(arr, 2)
A. [30, 40, 50, 10, 20]
B. [40, 50, 10, 20, 30]
C. [20, 30, 40, 50, 10]
D. [10, 20, 30, 40, 50]
Answer: A
Print fibonacciMod(n)
A. 3
B. 1
C. 0
D. 4
Answer: A
Print powerSum(x, y)
A. 8
B. 6
C. 9
D. 7
Answer: B
Explanation:
The pseudocode sums x repeated y times (equivalent to
multiplication).
For x = 2, y = 3, result = 2 + 2 + 2 = 6.
Print reverseDigits(n, 0)
A. 54321
B. 12345
C. 0
D. 123
Answer: A
Explanation:
The pseudocode reverses the digits of n.
For n = 12345, result = 54321.