C program to convert decimal to binary number

What is a Decimal number?

  1. A decimal numeral refers generally to the notation of a number in the decimal numeral system.
  2. The system consist these 0,1,2,3,4,5,6,7,8,9 numbers.
  3. Eg- 5,50,95,1452 .

What is a Binary number?

  1. A Binary numeral refers generally to the notation of a number in the Binary numeral system.
  2. The system consists of these 0,1 numbers.
  3. Eg- 101, 001,111,0101
There are methods for conversion of Decimal to Binary and Binary to decimal.


C Program to convert Decimal to Binary Number

    1. #include<stdio.h>
    2. #include<stdlib.h>
    3. int main()
    4. {
    5.    int a[10];
    6.    int n;
    7.    int i; 
    8.    printf("Enter decimal number \n");
    9.    scanf("%d",&n);
    10.       for(i=0;n>0;i++)
    11.           {
    12.              a[i]=n%2;
    13.              n=n/2;
    14.           } 
    15.     printf("\nBinary number is ");
    16.        for(i=i-1;i>=0;i--)
    17.            {
    18.               printf("%d",a[i]);
    19.            }  
    20. return 0;
    21. }