Decimal to binary C program

It’s a decimal to binary C program that inputs any decimal number from the user and calculates its binary equivalent, and print binary number on the screen.

To understand this program, it’s better you should know the following topics:

Program (1): to convert the decimal number to binary.

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int i,k,j;
printf("Enter any decimal number: ");
scanf("%d",&j);
printf("Binary nember is : ");
for(i=0;i<=15;i++)
{
  k=1<<(15-i);
  if((j & k)==0)
     printf("0");
  else
     printf("1");
}
getch();
}

Output (1)

Enter any decimal number: 18
Binary nember is : 0000000000010010

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

Your email address will not be published. Required fields are marked *