Run Length Encoding
June 13, 2012
Making both elements of an array zero
June 13, 2012

Output of a recursive function

What will be the output of the below function if n is positive ?

    void myFun(unsigned int n)
    {
        if(n != 0)
        {
            myFun(n/2);
            printf("%d", n % 2);
        }
    }

Solution:

The function prints the value of n in binary notation. For example: If n = 25 then the output will be 1 1 0 0 1.

Actually printing the remainders in reverse order (Head Recursion).

1 Comment

  1. Sonarutuari says:

    quite nice post, i certainly adore this web page, keep on it

Leave a Reply

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