I am trying to print binary numbers in C language. I'm having a problem with binary numbers starting with 0. When you try to keep it in the arrays and try to print it, random numbers come up, when you get input with scanf, the leading zero of the number disappears.
What should I do in this situation? Thank you in advance for your help.
int main(){
int binarys[3] ={01001001, 01100110, 00100000};
size_t i;
for(i=0; i<3; i++)
{
printf("%d\n", binarys[i]);
}
int binary;
printf("Enter a binary: ");
scanf("%d", &binary);
printf("%d", binary);
}
Output:
262657
294984
32768
Enter a binary: 01001001
1001001