newbie ask about decimal to binary in c++ -


this program suppose convert decimal binary somehow screw up

can 1 point out error me?

thanks lot

#include<conio.h> #include<stdio.h>     int main(){     int a;     int b[20];     int q = 0;     printf("decimal : ");scanf("%d",&a);     while(a>0)) {         b[q]=a%2;         a=a/2;               q++;          }while(a>0);     printf("binary : ");      (int = q-1; i>=0;i--){         printf("%d",b[q]);     }  } 

corrected code is:

#include<conio.h> #include<stdio.h> int main(){     int a;     int b[20];     int q = 0;     printf("decimal : ");scanf("%d",&a);     while(a>0) {         b[q]=a%2;         a=a/2;               q++;      }     printf("binary : ");      (int = q-1; i>=0;i--){         printf("%d",b[i]);     }  } 

you printing b[q] instead of b[i]


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -