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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...