#include
void main()
{
int num,i=0,start,end,j;
int bin[10]={0};
clrscr();
printf(" decimal to binary converting\n\n\n");
printf("enter START and END of range: "); //suppose if range is 1to50, then you
scanf("%d%d", &start,&end); //should enter START=1 and END=50
printf("\n\n\t the binary form is :\n\n");
for(num=start;num<=end;num++)
{
i=0;
j=num;
while(j>=1)
{
if(j==1)
{
bin[i]=1;
break;
}
bin[i]=j%2;
j=j/2;
i++;
}
printf("%4d -- ",num);
for(i=9;i>=0;i--)printf("%d",bin[i]);
printf("\n");
}
getch();
}
No comments:
Post a Comment