How to get each digit of int number from right to left in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int n = 7658;
     
    while(n) {
        std:: cout << n % 10 << '\n';
        n /= 10;
    }
}



/*
run:

8
5
6
7

*/

 



answered May 31, 2020 by avibootz
...