Skip to main content

Featured

Solve LeetCode 30 Substring with Concatenation of All Words in C++ using sliding window and frequency maps

Substring with Concatenation of All Words in C++ LeetCode 30 · sliding window · frequency maps · string_view Table of Contents Problem Statement Approach 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 Conclusion Problem Statement 30. Substring with Concatenation of All Words Given a string s and an array of strings words , where every word has the same length, find all starting indices of substrings that are a concatenation of every word exactly once, in any order. Approach This solution uses a sliding window and two frequency maps. Since every word has the same length, the string is checked in chunks of len characters. freq stores the required frequency of each word. temp stores the frequencies in the current window. count tracks the number of word-sized chunks in the window. If a word occurs too ...

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

๐ŸŒ™