0% found this document useful (0 votes)
317 views

Capgemini Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
317 views

Capgemini Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Placement Questions

Capgemini
1. What will be the output if limit = 6?

Read limit
n1 = 0, n2= 1, n3=1, count = 1;
while count <= limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
a)112358
b)12358
c)123581321
d)12358132
Answer :
Option a
First iteration of while loop: count <= limit. 1<=6. So, we will enter while loop.
count=2
Now we will print n3. So value of n3 is 1. 1 will be printed.
n3=n1+n2. So, n3=1,n1=1,n2=1
Second iteration: Count=3, Print n3. So 1 will be printed , n3=2, n1=1, n2=2
Third iteration: Count=4, Print n3. So 2 will be printed , n3=3, n1=2, n2=3
Fourth iteration: Count=5 , Print 3, n3=5, n1=3, n2=5
Fifth iteration: Count=6, Print 5, n3=8, n1=5, n2=8
Sixth iteration: Count=7, Print 8, n3=13, n1=8, n2=13
Hence output will be 112358
2. What is the output of the following pseudocode for a=3, b=8, c=7 ?
Integer funn(integer a,integer b, integer c)
if ((a^8) < 8)
c=a+c
c=a+c
End If
Return a+b+c
a)18
b)12
c)23
d)29
Answer: a)18
a=3 (0011) 8(1000)
a^8 - 0011
1000
1011
a^8 < 8 -> 11<8 -> False
So, a+b+c = 3+8+7 = 18 will be printed
3. What will be the space required for this piece of code?
int sum (int B[], int n)
{
int s = 0, j;
for (j = 0; j < n; j++)
s = s + B[i];
return s;
}// sizeof(int) = 2 bytes
a)2n+8
b)2n+4
c)2n
d)2n+2
Answer:
a) 2n+8
There are n elements in the array and the int data type acquires 2 bytes, so there will be
2n bytes acquired.
The int array occupies 4 bytes.
The s variable will occupy 2 bytes.
The j variable will occupy 2 bytes.
So total=2n+4+2+2=2n+8 bytes.
4. What is the output of the following code?
Character *ptr
Set *ptr= ‘Pointers’
Print *&*&*ptr
a)Segmentation fault
b)P
c)Compiler error
d)Pointers
Answer:
b)P
* - Dereferencing pointer
& - Referencing pointer
Both cancel out each other and print the output as ‘P’
5. Which of the following permutations can be obtained in the output using a stack
assuming that the input is in the sequence 1, 2, 3, 4, 5 in that order?
a) 3, 4, 5, 1, 2
b) 3, 4, 5, 2, 1
c)1, 5, 2, 3, 4
d)5, 4, 3, 1, 2
Answer:
b) 3, 4, 5, 2, 1
In a stack, first 1 and 2 are pushed. Then 3 is pushed and popped from the stack. Then 4 is
pushed and popped and then 5. 1 and 2 are popped from the stack which will be
permutation obtained.
6. Evaluate the postfix expression:
12+3*42-31+*-
a) 3
b) 1
c) 0
d) 2
Answer:
b) 1

7. Which of the data structures can have more than one logical way of traversing ?
a) Arrays
b) Linked list
c) Queue
d) Tree
Answer: d) Tree
Tree can be traversed by BFS, DFS, Inorder, Preorder, Postorder.
8. Which of the following is true concerning the directed graph shown below?
a)Only two topological orderings are possible
b)Only one topological ordering is possible
c)More than two topological orderings are possible
d) No topological ordering is possible
Answer:
d) No topological ordering is possible
Topological ordering can be calculated for only directed acyclic graphs. So the given graph
is a cyclic graph and no topological ordering is possible for the given graph.
9. What will be the output of the following pseudocode for input a = 30, b = 60, C = 90?
Integer a, b, c, sum
Read a, b, c
Set sum = a + b + c
if ((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT EQUALS 0) and (c NOT EQUALS
0))
Print " Success"
Otherwise
Print "Fail"
End if
a)Success b)Fail
c)Compilation error d)None of the above
Answer:
a)Success
a = 30, b = 60, C = 90sum=180((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT
EQUALS 0) and (c NOT EQUALS 0))
So, (true) and (true) and (true) and (true)
So, output will be "success"
10. What will be the output?
#include <iostream>
using namespace std;
int main()
{
int a = 32, *ptr = &a;
char ch = 'A', &cho = ch;
cho += a; *ptr += ch;
cout << a << ", " << ch << endl;
return 0;
}
a)129,a b)32,A c)129,A d)32,a
Answer: 129,a
The “ptr” variable is a pointer which holds the address of variable “a”. And “*ptr” returns the value of
“a” variable. “cho” is a reference variable to “ch”. So any change made to “cho” will be reflected to
“ch”. As such, when “cho” is increased by 32, it adds to the ASCII value of “A”(which is 65), and this
results to 97 which is the ASCII value of “a”(from the alphabet). So this “a” gets stored in “ch”. As for
when “*ptr” is incremented by “ch”, it gives value 97+32=129
11. Find the missing value in the grid.

Answer:
12. The below two grid follows a rule. Find the set of grid
that follows the rule.

Answer: 1 and 3
13. Put the red ball into the hole in minimum number of steps
Answer:
14. In this challenge, a grid with many coordinates will be shown with a point highlighted
and then two figures.
• First remember the highlighted grid position
• Simultaneously, mark if the next two shown figures are symmetrical or not
• At the end mark all the highlighted grid in last slide

Answer : Yes
Answer : Yes

Answer: No
Now mark the points in order,

Answer:

15. Behavioral Competency questions


I.
1. I generally do not misplace things.
2. I am very organised
II.
1. I like to summarize everything at the end of the meeting
2. I like to write down points simultaneously while having a meeting
a)Agree b)Slightly disagree
c)Slightly disagree d)Disagree
16. Find the maximum & minimum of two numbers in a single line without using any
condition & loop.

Answer:
void main ()
{
int a=15, b=10;
printf (“ max = %d, min = %d”, ((a+b) + abs(a-b)) /2, ((a+b) – abs (a-b)) /2);
}
17. Write a program to print 100 times “Hello” without using loop & goto statement.

Answer:
void main()
{
show (1, 100);
}
show (int x, int y)
{
if (x>=y)
return;
printf (“\n Hello”);
show (x+1, y);
}
18. Write a program to check for equality of two numbers without using arithmetic or
comparison operator
Answer:
#include<iostream>
using namespace std;
int main(){
int a = 132;
int b = 132;
if ( (a ^ b) )
cout<<"a is not equal to b";
else
cout<<"a is else to b";
return 0;
}
19. Write different ways to swap the given numbers
i. Using temporary variable
#include <stdio.h>
void main()
{
int x=10, y=20, temp;
printf("Before Swapping\n x = %d\n y = %d\n", x, y);
temp = x;
x = y;
y = temp;
printf("After Swapping\n x = %d\n y = %d\n", x, y);
}
ii. Without using temporary variable
#include <stdio.h>
void main()
{
int x=10, y=20;
printf("Before Swapping\n x = %d\n y = %d\n", x, y);
x=x+y;
y=x-y;
x=x-y;
printf("After Swapping\n x = %d\n y = %d\n", x, y);
}
iii. Using bitwise XOR operator
#include <stdio.h>
void main()
{
int x=10, y=20;
printf("Before Swapping\n x = %d\n y = %d\n", x, y);
x=x^y;
y=x^y;
x=x^y;
printf("After Swapping\n x = %d\n y = %d\n", x, y);
}
iv. Using pointer
#include <stdio.h>
void main()
{
int x=10, y=20,*ptr1,*ptr2,temp;;
printf("Before Swapping\n x = %d\n y = %d\n", x, y);
ptr1 = &x;
ptr2 = &y;
temp = *ptr2;
*ptr2 = *ptr1;
*ptr1 = temp;
printf("After Swapping\n x = %d\n y = %d\n", x, y);
}
v. Using user defined function
#include <stdio.h>
void swap(int*, int*); //function declaration
void main()
{
int x=10, y=20;

printf("Before Swapping\nx = %d y = %d\n", x, y);


swap(&x, &y); //function call
printf("After Swapping\nx = %d y = %d\n", x, y);
}
//function definition
void swap(int *ptr1, int *ptr2)
{
int temp;
temp = *ptr2;
*ptr2 = *ptr1;
*ptr1 = temp;
}

You might also like