To convert a decimal number to a binary number
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
long b[20], n, r, c = 0, i;
clrscr();
printf("Enter a decimal number : ");
scanf("%ld", &n);
while(n > 0)
{
r = n % 2;
b[c] = r;
n = n / 2;
c++;
}
printf("\nThe binary equivalent is : ");
for(i = c - 1 ; i >= 0 ; i--)
printf("%ld", b[i]);
getch();
}
Output:
Enter a decimal number : 12
The binary equivalent is : 1100
-
CreatedOct 15, 2014
-
UpdatedDec 30, 2019
-
Views3,482
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order