How to output numbers in binary form in the C language?

In C language, you can use the format specifier “%b” with the printf function to output numbers in binary form. Below is an example code:

#include <stdio.h>

int main() {
    int num = 10;
    
    printf("The binary representation of %d is %b\n", num, num);
    
    return 0;
}

Running this code will result in the following output:

The binary representation of 10 is 1010
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds