Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

Octal to Binary Conversion in C Program

✅ Octal to Binary Conversion in C

#include<stdio.h>

int main()
{
    int octal, remainder;

    printf("Enter an octal number: ");
    scanf("%d", &octal);

    printf("Binary equivalent: ");

    while(octal != 0)
    {
        remainder = octal % 10;

        switch(remainder)
        {
            case 0: printf("000 "); break;
            case 1: printf("001 "); break;
            case 2: printf("010 "); break;
            case 3: printf("011 "); break;
            case 4: printf("100 "); break;
            case 5: printf("101 "); break;
            case 6: printf("110 "); break;
            case 7: printf("111 "); break;
            default: printf("Invalid Octal Digit!");
        }

        octal = octal / 10;
    }

    return 0;
}
  

๐Ÿ“˜ Explanation:

This C program converts an octal number into its binary equivalent using switch case logic.

  • Each octal digit (0–7) is converted into a 3-bit binary number.
  • The program extracts digits using modulus operator (% 10).
  • Switch case is used to map each digit into binary form.
  • The loop continues until the number becomes 0.

This is a simple and efficient number system conversion method.

๐Ÿงพ Sample Output:

Enter an octal number:
17
Binary equivalent: 111 001
  

๐Ÿ”‘ Keywords:

octal to binary in C, switch case program, number system conversion, binary conversion logic, C programming basics, C examples

๐Ÿ“Œ Hashtags:

#CProgramming #OctalToBinary #SwitchCase #NumberSystem #LogicInC #1printf

Comments

Popular Posts

๐ŸŒ™