Decimal to Binary

C Programming

C Programming Examples

#include<stdio.h>

int main() {
	int decimal, binary = 0, i = 1;
	printf("Welcome to Decimal to Binary converter\n");
	printf("Enter a decimal number: ");
	scanf("%d",&decimal);
	while(decimal != 0) {
		binary += (decimal % 2) *i;
		i *= 10;
		decimal /= 2;
	}
	printf("Binary value is: %d\n",binary);
	return 0;
}


          /****** Output ******/
          

Welcome to Decimal to Binary converter

Enter a decimal number: 5

Binary value is: 101

Learn more about Decimal and Binary