Fri Jun 01 2018

Decimal to Binary

C Programming2653 views

File Name: decimal-to-binary.c

#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
Reference:

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