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

Find Greatest of Three Numbers in C

Find Greatest of Three Numbers in C

✅ Find the Greatest of Three Numbers in C

#include <stdio.h>

int main() {
    int a, b, c;

    // Input
    printf("Enter three numbers:\n");
    scanf("%d %d %d", &a, &b, &c);

    // Logic to find greatest
    if (a >= b && a >= c) {
        printf("The greatest number is: %d\n", a);
    } else if (b >= a && b >= c) {
        printf("The greatest number is: %d\n", b);
    } else {
        printf("The greatest number is: %d\n", c);
    }

    return 0;
}
  

๐Ÿ“˜ Explanation:

This C program takes three integers as input and determines the greatest among them using simple conditional statements. It compares the three numbers using nested if-else blocks:

  • First checks if a is greater than or equal to both b and c.
  • If not, then checks if b is greater than or equal to the other two.
  • If both conditions fail, then c is the greatest by default.
This approach ensures correct output even if the numbers are equal.

๐Ÿงพ Sample Output:

Enter three numbers:
12 45 33
The greatest number is: 45
  

๐Ÿ”‘ Keywords:

Greatest of three numbers, if else in C, compare numbers in C, logic building in C, beginner level C program, C programming basics

๐Ÿ“Œ Hashtags:

#CProgramming #BeginnerC #MaxOfThree #ComparisonLogic #IfElseC #CodingBasics

Comments

Popular Posts

๐ŸŒ™