by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to convert decimal number into binary number. Binary number has the base of 2. In this program user declare the variable and then the while condition in while condition (n>0). That will manipulated with a[d]=n%2. And then division with 2. Here after the increment operator and for printing out the binary number user uses the loop statement that will generate the binary number on the display.

Problem Statement:  
This is c program that asks the user to convert Decimal number into Binary.

  1. Declaring the variable.
  2. Using while condition.
  3. Divide the number with required quotations.
  4. Using loop statement.
  5. Display result on the screen.

Here is C source code for calculating the gross salary of employees. The output of this program shown below.

#include<stdio.h>

void main()
{
        int n,d=0,j,a[9];
        clrscr();
        printf("Enter the Integer which u want to Convert Decimal to Binary : ");
        scanf("%d",&n);
        while(n>0)
               {
                    a[d]=n%2;
                    n=n/2;
                    d++;
               }  
                    printf("After Converting Decimal to Binary is : ");
                    for(j=d-1;j>=0;j--)
                         printf("%d",a[j]);
                         getch();
}
Output ;

DECIMAL to BINARY conversion - C program



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.