Thursday, 21 June 2012

write a c program to convert decimal number into binary


/*write a c program to convert decimal number into binary */
#include<stdio.h>
#include<conio.h>
void main()
{
int dec,no,x[20];
int i,k=0;
clrscr();
printf("enter the number");
scanf("%d",&dec);
while(dec!=1)
{
no=dec%2;
x[k]=no;
k++;
dec=dec/2;
}

x[k]=1;
printf("the binary conversion is :");
for(i=k;i>=0;i--)
{
printf("%d",x[i]);
}
getch();
}
/*enter the number7
the binary conversion is :111                                                
                                                                             
  */

No comments: