Hi,
I am trying to write a program that will separate the digits of a non-negative integer and will print them each two spaces a apart but I have to avoid using arrays. For example if input is:
12345
then output should be:
1 2 3 4 5
I have written the following program for this purpose:
int main()
{
int number;
cout << "Enter a number to separate it\'s digits: ";
cin >> number;
while (number != 0)
{
cout << number%10 << " ";
number /= 10;
}
cout << endl;
system("pause");
return 0;
}
It works pretty well. The only problem with this program is that it prints the digits in reverse order as they appear in the number entered i.e. for the above given example, it will print:
5 4 3 2 1
instead of:
1 2 3 4 5
can someone please suggest a way to accomplish the desired behavior without using arrays or strings??