You are here : Home >> All Company Study Materials >> Capgemini Archive >> Capgemini Programming Questions
Q41. function g(int n)
{
if (n > 0) return 1;
else return -1;
}
function f(int a, int b)
{
if (a > b) return g(b-a);
if (a < b) return g(a-b);
return 0;
}
If f(a,b) is called, what is returned?
A. Always -1
B. 1 if a > b, -1 if a < b, 0 otherwise C. -1 if a > b, 1 if a < b, 0 otherwise
D. 0 if a equals b, -1 otherwise
Ans. D
Q42. function g(int n)
{
if (n > 0) return 1;
else return -1;
}
function f(int a, int b)
{
if (a > b) return g(a-b);
if (a < b) return g(b-a);
return 0;
}
If f(a,b) is called, what is returned?
A. 1 if a > b, -1 if a < b, 0 otherwise B. Always +1 C. 0 if a equals b, +1 otherwise D. -1 if a > b, 1 if a < b, 0 otherwise
Ans. C
Q43. function g(int n)
{
if (n > 0) return 1;
else return -1;
}
function f(int a, int b)
{
if (a > b) return g(a-b);
if (a < b) return g(-b+a);
return 0;
}
If f(a,b) is called, what is returned?
A. Always +1
B. 1 if a > b, -1 if a < b, 0 otherwise C. -1 if a > b, 1 if a < b, 0 otherwise
D. 0 if a equals b, -1 otherwise
Ans. B
Q44. function g(int n)
{
if (n > 0) return 1;
else return -1;
}
function f(int a, int b)
{
if (a > b) return g(b-a);
if (a < b) return g(-a+b);
return 0;
}
If f(a,b) is called, what is returned?
A. Always +1
B. -1 if a > b, 1 if a < b, 0 otherwise C. 1 if a > b, -1 if a < b, 0 otherwise
D. 0 if a equals b, -1 otherwise
Ans. B
Q45. Consider the following code:
for i= m to n increment 2
{ print “Hello!” }
Assuming m < n and exactly one of (m,n) is even, how many times will Hello be
printed?
A. (n – m + 1)/2
B. 1 + (n – m)/2
C. 1 + (n – m)/2 if m is even, (n – m + 1)/2 if m is odd
D. (n – m + 1)/2 if m is even, 1 + (n – m)/2 if m is odd
Ans. A