PART A
Consider the code fragment written in C below :
void f (int n)
{
if (n LessThanOrEqualTo 1) {
printf ("%d", n);
}
else {
f (n/2);
printf ("%d", n%2);
}
}
What does f(173) print?
A)010110101
B)010101101
C)10110101
D)10101101
PART B
Consider the code fragment written in C below :
void f (int n)
{
if (n LessThanOrEqualTo 1) {
printf ("%d", n);
}
else {
f (n/2);
printf ("%d", n%2);
}
}
Which of the following implementations will produce the same output for f(173) as the above code?
P1
void f (int n)
{
if (n/2) {
f(n/2);
}
printf ("%d", n%2);
}
P2
void f (int n)
{
if (n LessThanOrEqualTo1) {
printf ("%d", n);
}
else {
printf ("%d", n%2);
f (n/2);
}
}
(A) Both P1 and P2
(B) P2 only
(C) P1 only
(D) Neither P1 nor P2