Decimal to Binary

#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

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!