Showing posts with label Program to convert decimal no. to binary. Show all posts
Showing posts with label Program to convert decimal no. to binary. Show all posts

Wednesday, July 20, 2011

Program to convert decimal no. to binary

/*Serial No.56     [swami28.cpp]*/

/*NOTE::this program works good upto decimal value 31. */
#include<stdio.h>
#include<conio.h>
binary(int);
void main()
{
int value,num;
clrscr();
printf("Enter the any decimal number==>");
scanf("%d",&num);
value=binary(num);
printf("\nBinary of %d is== %d",num,value);
getch();
}
binary(int d)
{
 int bin=0,rem,b=1;
 b=1;
 if(d>0)
 {
 rem=d%2;
 bin=rem*b+binary(d/2)*b*10;//recursive function call
 }
 return(bin);
}