...
Number-Systems
January 11, 2024
GATE 1993
January 12, 2024
Number-Systems
January 11, 2024
GATE 1993
January 12, 2024

Question 11093 – Programming

What is the output printed by the following program?

#include
int f(int n, int k)
{
    if (n == 0)
        return 0;
    else if (n % 2)
        return f(n/2, 2*k) + k;
    else return f(n/2, 2*k) - k;
}
int main ()
{
    printf("%d", f(20, 1));
    return 0;
}

Correct Answer: C

Question 3 Explanation: 

Hence, 9 is the answer.
A
5
B
8
C
9
D
20

Leave a Reply

Your email address will not be published. Required fields are marked *