Monday, January 2, 2012

C program for DECIMAL to BINARY conversion

/* program for DECIMAL to BINARY converter */

#include
void main()
{
int num,i=0,bin,next;
clrscr();
printf(" decimal to binary converting\n\n\n");
printf("enter any decimal no. ");
scanf("%d", &num);
printf("please note that the binary form is represented in the\n form
(LSB ...MSB)\n");
printf("\n\n\t The binary form is :");


while(num>=2)
{
bin=num%2;
num=num/2;
printf("%d",bin); //logic can easily implemented using ARRAYs
if(num==1) //but i am not using arrays here.
printf("1"); //this is the MSB
}

getch();
}

No comments:

Post a Comment