0% found this document useful (0 votes)
23 views11 pages

Capgemini 2024 - Pseudo Code Trainer Handout Set 2

The document contains a series of programming questions and pseudocode examples, focusing on output predictions, error identification, and data structure implementations. It covers topics such as stack and queue implementations, pseudocode syntax, and various programming concepts. Each question is followed by multiple-choice answers and explanations for the correct options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views11 pages

Capgemini 2024 - Pseudo Code Trainer Handout Set 2

The document contains a series of programming questions and pseudocode examples, focusing on output predictions, error identification, and data structure implementations. It covers topics such as stack and queue implementations, pseudocode syntax, and various programming concepts. Each question is followed by multiple-choice answers and explanations for the correct options.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

COMPANY SPECIFIC SERIES

CAPGEMINI– PSEUDO CODE - TRAINER HANDOUT SET 2

1. What will be the output for the input 3,8,7,5,2,9,1,4,45,81,11,27?


begin
initialize counter to 0
initialize accumulator to 0
loop
read input from keyboard
accumulate input
increment counter
while counter < 10
calculate average
print sum
print average
end
a) 203 b) 203 c) 0 d) None of the mentioned
0 17 17
Explanation: Average will not be calculated because counter>10

2. How many stacks are needed to implement a queue.


Consider the situation where no other data structure like arrays, linked list is available to you.
a) 1 b) 2 c) 3 d) 4
Explanation: A queue can be implemented using two stacks

3. How many queues are needed to implement a stack.


Consider the situation where no other data structure like arrays, linked list is available to you.
a) 1 b) 2 c) 3 d) 4
Explanation: A stack can be implemented using two queues

4. What is the output of this program?

a) Temperature in Fahrenheit is 41.00 b) Temperature in Fahrenheit is 37.00


c) Temperature in Fahrenheit is 47.000000 d) Compilation Error
Explanation: calculate the (9/5)*c + 32, Ans will print in float 37.0

1
5. How do you initialize an array?
a) int arr[3]=(1,2,3) b) int arr(3)={1,2,3}
c) int arr[3]={1,2,3} d) int arr(3)=(1,2,3)
Explanation: Syntax to initialize an array int arr[3]={1,2,3}

6. What is the output of this program?

a) 2 b) 1 c) Compiler Error d) None of the above


Explanation: Main function will call foo(1), so foo() will print 2.

7. What is the output of this program?

a) -8 b) -4 c) Divide by zero error d) Compiler error


Explanation:
i+j/3 + i+j
-6+1 + -6+3
-6+1-3
-6-2
-8

8. Pseudocode is ____.
a) data that have been encoded for security.
b) the incorrect results of a computer program.
c) a program that doesn’t work.
d) a description of an algorithm similar to a computer language.

9. The operation performed in below pseudo code


Input: A list of numbers
1. Set Sum to 0
2. While there are more numbers
2.1 Add the current number to Sum
End loop
3. Return Sum

2
End
a) Addition b) Multiplication c) Summation d) None of the mentioned
Explanation: Addition is usually used to denote summation of 2 numbers, whereas summation is used for
sequences of numbers.

10. What will be the error/output?

a) 4 b) 0 c) 0.5 d) 1
Explanation: 0, data bits are lost for the above shift operation hence the value is 0.

11. What will be the error/output?

a) A b) Garbage value c) 65 d) 97
Explanation: 65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII
value is 65 and is printed.

12. What will be the error/output?

a) Overflow error at runtime b) A c) B d) Compile error


Explanation: A, the range of ASCII values for the ASCII characters is 0-255. Hence the addition operation
circulates back to ‘A’

3
13. What will be the output of the following pseudocode?

a) 0 b) 1 c) 2 d) 4
Explanation: Make shift operation for given value

14. What will be the output of the following pseudocode for n =8?

a) 32 b) 16 c) 8 d) 12
Explanation: Recursion call will return the value of 2*(2*(4)) =16

15. What will be the output of the following pseudocode?

a) 18 23 45 56 4 6 45 b) 18 23 45 56 4 c) 23 45 56 4 6 45 d) Error
Explanation: for loop will run till i<=x-2.

16. What will be the output of the following pseudocode?

a) 11 5 b) 8 5 c) 7 9 d) 13 7
Explanation:
for loop will run till conditions gets a<=4.

4
for(a=1;a<=4;a++){
c = a + b;
if(((b + c) % 10) != 0)
c = c + a;
else
d = d + a;
}

17. What will be the output of the following pseudocode?

a) 112 b) 433 c) 231 d) 332


Explanation: Check while (c>0) and run the statements

18. The following pseudocode is an example of a(n) ____ structure:


get number
while number is positive
add to sum
get number
a) Sequence b) Decision c) Loop d) Nested

19. The following pseudocode is an example of ____.


do stepA
do stepB
if conditionC is true then
do stepD
else
do stepE
endif
while conditionF is true
do stepG
endwhile
a) Nesting b) Stacking c) Posttest d) Pretest

20. The output of an AND gate with three inputs, A, B, and C, is HIGH when ________.
a) A = 1, B = 1, C = 0 b) A = 0, B = 0, C = 0 c) A = 1, B = 1, C = 1 d) A = 1, B = 0, C = 1

21. What will be the output / error?

5
a) Fffffffe b) Fffe c) dependent on the compiler d) Error
Explanation: Output is dependent on the compiler. For 32 bit compiler it would be fffffffe and for 16 bit it
would be fffe.

22. What will be the output / error?


int main()
{
int x, y = 5, z = 5;
x = y==z;
printf("%d", x);

getchar();
return 0;
}
a) 0 b) 1 c) Compiler error d) runtime error
Explanation: Since y is equal to z, value of the expression y == z becomes 1 and the value is assigned to x
via the assignment operator.

23. What will be the output/error?

a) Hi b) Compile time error c) Nothing d) Varies

24. What will be the output/error?

a) Address of x b) Junk value c) 0 d) Run time error

6
25. What will be the output/error?

a) Compile time error b) 0 c) Undefined behaviour d) Segmentation fault

26. What will be the output of the following pseudocode?


Integer tem, num, count, i, j, k
set temp=1,num=5, count=0
for each i from 0 to num
for j from num+temp to 3*num incrementing by 2
for k from 1 to temp incrementing by 3
count++
end for
end for
end for
Print count
a) 25 b) 26 c) 24 d) 28
Explanation: for loop will run all 3 loop conditiongets false. Then count value will be 25

27. What will be the output of the following pseudocode?

7
a) 0 b) 10 c) 18 d) 14
Explanation: All three for loop will run till all conditions gets false. Also need to check the if condition
S%2==0. So the count value will be 18

28. What will be the output of the following pseudocode for x = 3 and y =2?

a) 8 5 2 b) 4 5 6 c) 7 6 5 d) 8 7 3
Explanation: The function fun() calculates and returns ((1 + 2 … + x-1 + x) y+3) which is (x-1,y+3)

29. What will be the output of the following pseudocode?

a) 3 -13 b) 6 -6 c) 3 4 d) 12 -6
Explanation: Ans c=6 and d=-6

30. What is the output of this C code?

a) 9 b) 8 c) 18 d) 19

31. What is the output of this C code?

8
a) 1 2 3 4 5 b) 1 2 3 4 c) Compile Time Error d) Stack Overflow
Explanation: Stack Overflow, It is thrown when the amount of call stack memory allocated by JVM is
exceeded.

32. What is the output of this C Code?

a) Compile Time Error b) 4 c) 4.0000000 d) 4.4


Explanation: Since the variable k is defined both as integer and as float, it results in an error.
Output:
$ cc pgm8.c
pgm8.c: In function ‘main’:
pgm8.c:5: error: conflicting types for ‘k’
pgm8.c:4: note: previous definition of ‘k’ was here
pgm8.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘double’
pgm8.c:7: error: expected ‘;’ before ‘}’ token

33. What will be the data type of the result of the following operation?
(float)a * (int)b / (long)c * (double)d
a) Int b) Long c) Float d) double
Explanation: It will return the value in Double

34. Consider a B-tree of order 4 and is built from scratch by 10 successive insertions. What would be the
maximum number of node splitting operations that take place?
a) 6 b) 3 c) 4 d) 2
Explanation: A B-tree of order m contains n records and each contains b records on average then the tree will
have about n/b leaves. If we split k nodes along the path from leaves then

9
k<=1+logm/2 [n/b]
here n=10,b=3,m=4 so
k<=1+log4/2 [n/b]
k<=1+log2 4
k<= 1+2
k<=3

35. Which of the following logic is used to produce loops in program logic when one or more instruction
may be executed several times depending on some conditions?
a) Iteration Logic b) Selection Logic c) Sequence Logic d) Decision Logic

36. What will be the output of the following pseudocode?

a) Infinite loop b) No output c) 1 2 3 4 5 d) 5 4 3 2 1

37. What will be the output of the following pseudocode?

a) Infinite loop b) No output c) 1 4 7 10 13 d) 1 4 7 10 13


1 4 7 10 13
Explanation: while loop will run 2 times

38. What will be the output of the following pseudocode?


Integer a,b
set n=10, b=15
a=n<<4
b=n>>2
c=n<<5
d=n>>3
Print a

10
Print b
Print c
Print d
a) Can’t be determined b) 160 2 320 1 c) 40 2 320 0 d) 1 2 3 4
Explanation: Once all shift operator are done, answer will be 160 2 320 1

39. What will be the output of the following pseudocode?

a) Can’t be determined b) Compilation error c) Runtime error d) 2


Explanation: ++*a here *a will represent the address of array. head address value will be increment by 1.

40. What will be the output of the following pseudocode?

a) Infinite b) Error c) Hai Hai d) Hai


Explanation: Hai Hai, while loop will run till condition gets False.

11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy