Accenture Psedocode - 8
Accenture Psedocode - 8
Accenture Psedocode - 8
Which combination of the integer variables x, y and z makes the variable a get the value 4 in
the following expression?
a = (x > y)? ((x > z)? x : z): ((y > z)? y : z)
A) x = 3, y = 4, z = 2
B) x = 6, y = 5, z = 3
C) x = 6, y = 3, z = 5
D) x = 5, y = 4, z = 5
Answer A
20. What is the value printed by the following program
int f(int *a, int n)
{
if(n <= 0) return 0;
else if(*a % 2 == 0) return *a + f(a+1, n-1);
else return *a - f(a+1, n-1);
}
int main()
{
int a[] = {12, 7, 13, 4, 11, 6};
printf("%d", f(a, 6));
getchar();
return 0;
}
A) -9
B) 5
C) 15
D) 19
Answer C
4. Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun(unsigned long int n) {
unsigned long int i, j, j=0, sum = 0;
for (i = n; i > 1; i = i/2) j++;
for ( ; j > 1; j = j/2) sum++;
return sum;
}
The value returned when we call fun with the input 2^40 is
A) 4
B) 5
C) 6
D) 40
Answer B
5. Consider the following program written in pseudo-code. Assume that x and y are integers.
Count (x, y) {
if (y != 1) {
if (x != 1) {
print("*") ;
Count (x/2, y) ;
}
else {
y=y-1;
Count (1024, y) ;
}
}
}
The number of times that the print statement is executed by the call Count(1024,
1024) is ______.
A) 10230
B) 10231
C) 10232
D) 10233
Answer A
8. Consider the C program fragment below which is meant to divide x and y using repeated
subtractions.
The variables x, y, q and r are all unsigned int.
while (r >= y) {
r = r - y;
q = q + 1;
}
Which of the following conditions on the variables x, y, q and r before the
execution of the fragment will ensure
that the loop terminates in a state satisfying the condition x == (y*q + r)?
A) (q == r) && (r == 0)
B) (x> 0) && (r == x) && (y > 0)
C) (q == 0) && (r == x) && (y > 0)
D) (q == 0) && (y > 0)
Answer C
11. What is the output of the following C code? Assume that the address of x is 2000 (in
decimal) and an integer requires four bytes of memory.
#include <stdio.h>
int main()
{
unsignedint x[4][3] = {{1, 2, 3}, {4, 5, 6},
{7, 8, 9}, {10, 11, 12}};
printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
A) 2036, 2036, 2036
B) 2012, 4, 2204
C) 2036, 10, 10
D) 2012, 4, 6
Answer A