~riderius/cpp-code

cpp-code/reverse_int.cpp -rw-r--r-- 286 bytes
380d65aariderius digits_analysis.cpp: argv[1] can replace n 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int reverse(int n);

int main()
{
    using namespace std;

    int k;
    cin >> k;
    cout << reverse(k) << '\n';
}

int reverse(int n)
{
    int result = 0;
    while (n != 0) {
        result = result * 10 + n % 10;
        n /= 10;
    }
    return result;
}