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

3Sum - Leetcode solution - How i turned into two-pointer approach?

  class Solution {     public List < List < Integer >> threeSum ( int [] nums ) {         Arrays . sort (nums); // first sort...