Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

my program prints binary in reverse order i.e for 10 it shouldprint 1010 but it

ID: 3613784 • Letter: M

Question

my program prints binary in reverse order i.e for 10 it shouldprint 1010
but it prints 0101 plz help? rectify any error in my prg
my prg is
# include <stdio.h>

int main (void)
{
int num;
clrscr();

printf ("Enter the no: to be converted into binary ");
scanf ("%d",&num);






while (num != 0)
{
printf ("%d",num % 2);
num = num /2;
}
getch();
return 0;
} rectify any error in my prg
my prg is
# include <stdio.h>

int main (void)
{
int num;
clrscr();

printf ("Enter the no: to be converted into binary ");
scanf ("%d",&num);






while (num != 0)
{
printf ("%d",num % 2);
num = num /2;
}
getch();
return 0;
}

Explanation / Answer

please rate - thanks without arrays # include #include int main() { int i,num,digit,answer=0,zeroes=0,found1=0; printf("Enter the no to be converted into binary: "); scanf("%d",&num); printf("%d in binary is: ",num); i=-1; while (num!=0)     {i++ ;     digit=num%2;     if(digit==1)      //must count the 0's before get a 1          found1=1;     else         if(found1==0)             zeroes++;                answer=answer*10+digit;     num=num/2;     } for(i=0;i