Skip to main content

Featured

C++ Program to Perform Linear Search on a Vector

  C++ Program to Perform Linear Search on a Vector Introduction In this C++ program, we will learn how to perform a Linear Search on a vector. The program first takes the size of the vector and its elements as input. Then it asks the user for the element to search. If the element is found, it displays the index where it is located. Otherwise, it displays a message indicating that the element is not found. C++ Program #include<bits/stdc++.h> using namespace std; int main() { int num, search, found = 0; cout << "Enter the size of the vector:" << endl; cin >> num; vector<int> v(num); cout << "Enter " << num << " elements in vector:" << endl; for(int i = 0; i < num; i++) { cin >> v[i]; } cout << "Enter element that you want to search:" << endl; cin >> search; for(int i = 0; i < num; i++) { ...

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

๐ŸŒ™