/* decimal to binary conversion using recursion */
#include<stdio.h>
#include<conio.h>
long binary(long n){
static long int bin=0,base=1;
if(n>0)
{
printf("%d",n%2);
bin=bin+n%2*base;
base*=10;
binary(n/2);
}
return bin;
}
main(){
long int n=100;
clrscr();
printf("\nbinary no is %ld",binary(n));
}
{
d=no%2;
no/=2;
bin=bin+base*d;
base*=10;
}
printf("\n%d",bin);
}
#include<stdio.h>
#include<conio.h>
long binary(long n){
static long int bin=0,base=1;
if(n>0)
{
printf("%d",n%2);
bin=bin+n%2*base;
base*=10;
binary(n/2);
}
return bin;
}
main(){
long int n=100;
clrscr();
printf("\nbinary no is %ld",binary(n));
}
/* decimal to binary conversion using loops */
main(){
int no=7;
long bin=0,base=1;
int d;
while(no){
d=no%2;
no/=2;
bin=bin+base*d;
base*=10;
}
printf("\n%d",bin);
}
No comments:
Post a Comment