Print Binary Numbers in C
In C programming language, you can use the printf function’s format string to output binary numbers. You can do this by specifying the format string as “%b” and passing in a decimal number as the parameter to print the corresponding binary number.
For example, to output the binary representation of the decimal number 10, you can use the following code:
#include <stdio.h>
int main() {
int decimalNumber = 10;
printf("Binary representation of %d is: %b\n", decimalNumber, decimalNumber);
return 0;
}
Executing the above code will output:
Binary representation of 10 is: 1010