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

C Program to Reverse a Number Using While Loop

✅ C Program to Reverse a Number Using While Loop

#include <stdio.h>

int main() {
    int num, reversed = 0, remainder;

    printf("Enter a number: ");
    scanf("%d", &num);

    while(num != 0) {
        remainder = num % 10;          
        reversed = reversed * 10 + remainder; 
        num = num / 10;                
    }

    printf("Reversed number = %d", reversed);

    return 0;
}
  

๐Ÿ“˜ Explanation:

This program reverses a given number using a while loop. It extracts digits one by one from the end and rebuilds the number in reverse order.

  • Take user input using scanf().
  • Use num % 10 to extract the last digit.
  • Multiply reversed number by 10 and add the extracted digit.
  • Remove last digit using num = num / 10.
  • Repeat until the number becomes 0.

This program is commonly asked in beginner coding interviews and programming exams.

๐Ÿงพ Sample Output:

Enter a number: 1234
Reversed number = 4321
  

๐Ÿ”‘ Keywords:

C program to reverse a number, reverse number in C using while loop, C programming examples, beginner C programs, number manipulation in C, C logic building program

๐Ÿ“Œ Hashtags:

#CProgramming #ReverseNumber #LearnC #CodingForBeginners #WhileLoop #1printf

๐Ÿ” Search Description:

Learn how to reverse a number in C using while loop. Beginner-friendly program with step-by-step explanation and sample output.

Comments

Popular Posts

๐ŸŒ™