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; ...

Binary to Octal Conversion in C

Binary to Octal Conversion in C

✅ Binary to Octal Conversion in C

#include<stdio.h>
int main( )
{
    int num, octal = 0, remainder, j = 1;
    printf("Enter the number:\n");
    scanf("%d", &num);
    while (num != 0)
    {
        remainder = num % 10;
        octal = octal + remainder * j;
        j = j * 2;
        num = num / 10;
    }
    printf("The octal equivalent value is %o\n", octal);
}
  

πŸ“˜ Explanation:

This program converts a binary number (entered as an integer) into its octal equivalent. - It processes each digit of the binary number from right to left. - For each digit, it multiplies by its corresponding positional weight in base-2 and adds it to `octal`. - The final result is printed using `%o`, which formats the number in octal form.

🧾 Sample Output:

Enter the number:
1010
The octal equivalent value is 12
  

πŸ”‘ Keywords:

Binary to Octal in C, Number Conversion in C, Beginner C Programs, Binary Conversion Logic, C Program Examples, %o format specifier

πŸ“Œ Hashtags:

#CProgramming #BinaryToOctal #BeginnerC #NumberConversion #OctalFormat #scanf #printf #whileLoop

Binary to Octal Conversion – Visual Explanation

Example: Convert Binary 101110 to Octal.

Step 1: Group binary digits from right in 3s:
Binary:     101 110

Step 2: Convert each 3-bit group to decimal (octal):
   101 -> 5
   110 -> 6

Octal Value: 56

This is how we convert binary numbers into octal by grouping every 3 bits.

Comments

Popular Posts

πŸŒ™