Step 1: Use the modulus operator (Number % 2) and store the remainder in an array.
Step 2: Divide that number by 2 (Number/2).
Step 3: Repeat step 2 until the number is greater than 0.
Step 4: Display array.
#include <stdio.h>
#include <conio.h>
int main()
{
int bin[10], num, i, j;
printf("Enter any number: ");
scanf("%d", &num);
printf("Binary Number of %d is = ",num);
for(i = 0; num > 0; i++)
{
bin[i] = num % 2;
num = num / 2;
}
for(j = i - 1; j >= 0; j--)
{
printf(" %d ", bin[j]);
}
getch();
return 0;
}
Enter any number: 55
Binary Number of 55 is = 1 1 0 1 1 1
--------------------------------
Process exited after 5.028 seconds with return value 0
Press any key to continue . . .