Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C Program: Print Binary Representation of a Number

Binary Representation of Number in C

✅ C Program: Binary Representation of a Number

#include<stdio.h>
int main( )
{
    unsigned int num;
    printf("Enter the number:\n");
    scanf("%u", &num);

    for(int i = 31; i >= 0; i--)
    {
        if(num & (1 << i))
            printf("1");
        else
            printf("0");
    }
    printf("\n");
}
  

πŸ“˜ Explanation:

This program prints the binary representation of an unsigned integer using bitwise operators.

  • The user inputs a number.
  • The loop checks all 32 bits (from MSB to LSB).
  • If the bit is set, it prints 1; otherwise, 0.
  • This uses the expression (num & (1 << i)) to test each bit.

🧾 Sample Output:

Enter the number:
5
00000000000000000000000000000101
  

πŸ”– Keywords:

C Program, Binary in C, Bitwise Operator in C, Binary Print, 32-bit Output, C Interview Questions, Unsigned Integer Handling

πŸ“Œ Hashtags:

#CProgramming #BitwiseOperators #BinaryOutput #InterviewPreparation #AdSenseReady #CodingBlog

Comments

Popular Posts

πŸŒ™