How to write a c program to print in binary format in c programming ?
Solution:
#include <stdio.h>
void printBinary(int n);
int main()
{
int n = 5;
printBinary(n);
return 0;
}
void printBinary(int n)
{
unsigned int i;
for(i = 1<<31; i >= 1; i >>= 1)
{
if(i & n) printf("1");
else printf("0");
}
}