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 ...

Print Prime Numbers Between Two Numbers in C

Print Prime Numbers Between Two Numbers in C

✅ Print Prime Numbers Between Two Numbers in C

#include <stdio.h>

int main() {
    int m, n, i, j, isPrime;

    // Input range from user
    printf("Enter the starting number (m): ");
    scanf("%d", &m);

    printf("Enter the ending number (n): ");
    scanf("%d", &n);

    printf("Prime numbers between %d and %d are:\n", m, n);

    for(i = m; i <= n; i++) {
        if (i < 2) continue;

        isPrime = 1; // Assume prime

        for(j = 2; j <= i / 2; j++) {
            if(i % j == 0) {
                isPrime = 0;
                break;
            }
        }

        if(isPrime) {
            printf("%d ", i);
        }
    }

    printf("\n");
    return 0;
}
  

๐Ÿ“˜ Explanation:

✅ The program reads two integers m and n.
✅ It loops from m to n and checks each number for primality.
✅ For each number, it checks if it’s divisible by any number from 2 to i/2.
✅ If no divisors are found, it's a prime and printed.

๐Ÿงพ Sample Output:

Enter the starting number (m): 10
Enter the ending number (n): 25
Prime numbers between 10 and 25 are:
11 13 17 19 23
  

๐Ÿ”‘ Keywords:

C prime number program, prime between two numbers, C beginner practice, loop logic, prime check algorithm in C

๐Ÿ“Œ Hashtags:

#CProgramming #PrimeNumbers #LoopingInC #BeginnerC #ProgrammingBasics #InterviewPrep

Comments

Popular Posts

๐ŸŒ™