Program to convert decimal to binary in c

Decimal to binary conversion in c programming language.
 C source code for decimal to binary conversion:


#include<stdio.h>


int main(){

    long int decimalNumber,remainder,quotient;

    int binaryNumber[100],i=1,j;


    printf("Enter any decimal number: ");

    scanf("%ld",&decimalNumber);


    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]);


    return 0;

}


Sample output:


Enter any decimal number: 50
Equivalent binary value of decimal number 50: 110010


No comments:

Post a Comment