Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

πŸŒ™