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
Author:Geekboots