by Dinesh Thakur

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