Answer:
<em>C++</em>
/////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int main() {
int number;
cout<<"Enter four digit positive integer: ";
cin>>number;
///////////////////////////////////////////////
int divisor = 1000;
int digit;
if ((number > 999) && (number < 9999)) {
for (int i=0; i<3; i++) {
digit = number/divisor;
number = number%divisor;
divisor = divisor/10;
cout<<digit<<endl;
}
cout<<number;
}
else {
cout<<"Invalid range!";
}
///////////////////////////////////////////////
return 0;
}
Explanation:
To accomplish the task, we need to use the divide and modulo operators.
To get each digit, we need to divide the variable number by the divisor (which is initialized to 1000).
We also need to reset the number variable to one less digit from the right. We can do this by number modulo divisor, which is assigned back to the number variable.
Finally we need to lower the divisor by 10 each time in the loop, to keep it in accordance with the above two operations.