Monday, June 28, 2010

c code for finding binary represenation of a number

Here we have to see a recursive procedure for finding the binary representation of a given number.
  •   The following code has O(logN) time complexity.
  •   The concept is to divide the number recursively and displays the result
  •   The following function void base(int num,int n) prints the output.
Here is the code

void base(int num,int n)              //num is the given number , n is 2
   {    if(num>1)                          
             base(num/n,n);
         printf("%d",num%n);
    }

No comments: