Question: I am trying to separate the digits of a number entered by the user. i get the digits in reversed order.For example, if input is 12345,I get 5 4 3 2 1 as output.

I had similar case while finding the binary of a number.
 can you explain me why this problem occurring and easy solution to this problem.

```
#include<iostream>
using namespace std;
int main()
{
cout << "Enter an integer " << endl;
int number;
cin >> number;

int n;
n = number%10;
number = number/10;
cout<<n<<'\n';
while(n!=0)
{   
    n = number%10;
    number = number/10;
    if(n==0)
        {
            break;
        }
    cout << n << '\n';
}
}

```

**If input is 12345**

**output is:**

```
5
4
3
2
1

```

Answer: 
You are not using correct logic to do the job.
When you use modulus operator then it gives the remainder and that will be last digit if modulus is performed with 10. And then you print that so it will always be the last digit and then you divide the number by 10, and the number is of integer type so it will remove the last digit and then the process starts again.

You can use array and print it.
But here you are using a simple variable so you need to reverse the number first.

I have written the code for the same and it does the job really fine.

```
#include<stdio.h>

void main()
{
  long int number,n = 0;
  int temp = 0;

  scanf("%ld",&number);
  while(number != 0)
  {
    temp = 0;
    temp = number % 10;
    n = (n * 10) + temp;
    number = number / 10;
  }
  while(n != 0)
  {
    temp = n % 10;
    printf("%d\n", temp);
    n = n / 10;
  }
}

```
As @GhostCat said. Math does a job here. I would recommend you sketch your algorithm and this may show you what's 'wrong' here. ^^

Can you show us what final output do you expect?
If it's just same order I might be an array with every digit with own index in right order.

Also your code has shortcoming at while loop condition; make an input which contains '0' digit at any position... your code will break. That's because your loop will run as long, as validating digit will be any number, but not 0, what does not make sense. This loop condition should look like this `while(number >= 0)`.