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;
  }
}

```
That is because your algorithm works on the smaller "rear" end of your number. 

Simple as that! 

```
 15 % 10 = 5
 10 % 10 = 1

```

That is why it would print 5 1 and not 1 5.

So, if you want to print the number as 1 5, you simply have to push those values into an array for example, and then print the array in reverse order.