Skip to main content

Featured

Solve LeetCode 3 Longest Substring Without Repeating Characters in C++ using the sliding window

Longest Substring Without Repeating Characters in C++ LeetCode 3 · sliding window · last index array 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 3. Longest Substring Without Repeating Characters Given a string s , find the length of the longest substring that contains no repeating characters. A substring is a continuous part of the string, so "pwke" is a subsequence of "pwwkew" but not a substring. Approach We use a sliding window . The window is the part of the string between start and end , and we always keep it free of repeated characters. An array lastIndex of size 128 remembers the most recent position of every ASCII ...

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

๐ŸŒ™