+ 1

Fix Below code error (convert decimal number into binary number system [array must be included] )

int i = 0; int input; int binaryNumber[i]; cout<<"Enter Decimal Number: "; cin>>input; while(input>0){ binaryNumber[i] = input % 2; input = input / 2; i++; } cout<<"Binary Convert Result is: "<<binaryNumber[i];

20th Aug 2018, 9:19 PM
ABDULLAH H.M
ABDULLAH H.M - avatar
1 Answer
+ 2
I made several changes to your code: https://code.sololearn.com/c1Frtbc07Iss/#cpp One of the errors with your code is the array that is initialized to have 0 integers. I simply initialized the array to 32. Another modification I made was to print out the array using a for loop, from the largest to smallest index. This way the most-significant bit is on the left. Other than that your algorithm for converting to binary works fine.
20th Aug 2018, 10:00 PM
Louie
Louie  - avatar