/*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);
}
/*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);
}
No comments:
Post a Comment
If you have any doubt, feel free to ask...