What wrong with my code anyone help me plz .It's a decimal to binary conversion . According to my code , the out will be 2 for 10 , 3 for 11 but it output always add the last value at the end like for 3 it shows 1110 , add the previous output . What should I do now ? help me plz ?
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
long int decimalNumber,quotient;
int binaryNumber[100],i=0,j;
printf("Enter any decimal number: ");
//scanf_s("%ld",&decimalNumber);
while(scanf_s("%ld",&decimalNumber)==1)
{
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf("Equivalent binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j>= 0;j--)
printf("%d",binaryNumber[j]);
printf("\n");
printf("Enter any decimal number: ");
}
return 0;
}