codescracker


c

C Program to Convert Decimal to Binary



« Previous Program Next Program »


Decimal to Binary Conversion in C

To convert decimal number to binary number in C programming, you have to ask to the user to enter the decimal number to convert it into binary number to display the equivalent value in binary

C Programming Code to Convert Decimal to Binary

Following C program ask to the user to enter any number in decimal to convert it into binary, then display the result on the screen :

/* C Program - Decimal to Binary Conversion */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	long int decnum, rem, quot;
	int binnum[100], i=1, j;
	printf("Enter any decimal number : ");
	scanf("%ld",&decnum);
	quot=decnum;
	while(quot!=0)
	{
		binnum[i++]=quot%2;
		quot=quot/2;
	}
	printf("Equivalent binary value of %d :\n",decnum);
	for(j=i-1; j>0; j--)
	{
		printf("%d",binnum[j]);
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program convert decimal to binary

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test