I'm attempting to write a programme in C++ to reverse a number. It works well with numbers like 1234, but when I try to enter a number like 5430, it displays 345, and the same with numbers that begin with zero, such as 0234, which displays 432.
Could someone please explain how to deal with zeros at the beginning and end of a sentence?
I simply need to save the number without converting it to a string.
using namespace std;
cin >> n;
int reverse = 0;
lastdigit = n % 10;
reverse = reverse * 10 + lastdigit;
n = n / 10;
cout << reverse<<endl;