Reversing digits of an integer
To understand the reversing digits of an integer we take an example. Suppose we take the five digits number from keyboard. For this, we use the modulo (%) operator.
Input: 12345
Output: 54321
So for doing as, we divide five digits number by 10 and take its remainder and print the remainder and quotient is again divided by 10 and take its remainder until the quotient become zero.
Logic:
while(n>0)
{
rem=n%10;
n=n/10;
printf("%d", rem);
}
Algorithm:
Step 1: Start
Step 2: Take five digits positive integer to be reversed.
Step 3: Take remainder of given number by the modulo operator.
Step 4: Divide quotient by 10.
Step 5: Repeat step 3 and 4 until n becomes zero.
Step 6. Print the value of remainder.
Step 7: Stop.