Converting a decimal number to a binary number

I am getting the correct binary number as output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

/*
Summary: Converts decimal number which is base 10 number system 0-9 to binary which is base 2 number system 0 and 1.
*/
#include<iostream>
using namespace std;

int main(){
	int decimalNumber, quotient;
	int binaryNumber[100], i = 1, j;

	cout<<"Enter any decimal number: ";
//	scanf("%ld",&decimalNumber);
   cin >> decimalNumber;
	quotient = decimalNumber;
	while(quotient != 0){
		binaryNumber[i++] = quotient % 2;
		quotient = quotient / 2;
	}

	cout<<"Equivalent binary value of decimal number  " << decimalNumber;
	for(j = i - 1 ; j > 0; j--)
	
    cout<< binaryNumber[j];

	return 0;
}

/*
Input: Enter any decimal number: 10
*/  

There are 2 extra bits in the output.
I get 101010.
I expect 1010.
Remove line 21.
Thanks last chance.
After removing that line I got the correct output
Topic archived. No new replies allowed.