Pages

Wednesday, March 26, 2025

code to print in reversed manner using while loop in C++

 #include <iostream>

using namespace std;

// code to print reverse manner
int main(){
    int n = 10829;

    while(n > 0){ // infinite loop until all digits are checked
        int lastDig = n % 10; // gets last digit
        cout << lastDig << " ";
        n /= 10; // removes the last digit, keeps remaining
    }

    return 0;

}

No comments:

Post a Comment

Encode and Decode Strings - NeetCode.IO Solution by me + gemini pro 3.0 explained

  class Solution {         // encode: List of Strings -> String     public String encode ( List < String > strs) {         Stri...