My problem is that I'm having to take a 5-digit integer input given by the user, and separate the integer into its individual digits. I then need to print those digits in reverse order and also print out the sum of those digits. Here is what I have coded so far to separate the 5-digit integer into its individual digits. Please note that I am limited to using integer division and modulo operators for separating the integer into its digits.
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a five-digit number: ";
cin >> number;
cout << number / 10000 << " ";
number = number % 10000;
cout << number / 1000 << " ";
number = number % 1000;
cout << number / 100 << " ";
number = number % 100;
cout << number / 10 << " ";
number = number % 10;
cout << number << endl;
return 0;
}
For example, when the user inputs a 5-digit number like 77602, the program should output it as
7 7 6 0 2 and the sum of the digits is 22.
How do I go about printing this in reverse order as well as the sum of the individual digits?
Edit: Few spelling and grammatical errors.