i wanna know if i could read any int from his both sides like "234" i want to record the inversed number like"432" is there a way to read the number from his other side?
#include <string>
#include <iostream>
#include <cstdlib>
int main()
{
usingnamespace std;
int number = 123456789; // initial value to be reversed
string input = to_string(number); // convert number to string
string output = "";
char temp;
int reversed_int; // will be: 987654321
for (size_t i = input.size(); i > 0; --i)
{
temp = input.at(i -1); // get current character
output += temp; // appending in reverse order happens here
}
reversed_int = atoi(output.c_str()); // convert reversed number back to int
// show result
cout << "original number was: " << number << endl;
cout << "in reversed order it is: " << reversed_int << endl;
cin.get();
return 0;
}