Search C Program | nimishsoft@gmail.com

Binary by recursion

/* Binary by recursion */

#include<stdio.h>
void binary(long);
int main()
{
 long n;
 printf("Type a value : ");
 scanf("%ld",&n);
 binary(n);
 return 0;
}

void binary(long n)
{
 if(n>1)
  binary(n/2);
 printf("%ld",n%2);
}

2 comments:

  1. Decimal To Binary..

    public static int ranjeetgreat(String str){
    double j=0;
    for(int i=0;i<str.length();i++){
    if(str.charAt(i)== '1'){
    j=j+ Math.pow(2,str.length()-1-i);
    }

    }
    return (int) j;
    }

    ReplyDelete