fastread homefastrread library fastread menu

C : Reverse a Number

Tutorial by:Manisha Dubey      Date: 2016-06-17 03:38:10

❰ Previous Next ❱

Example to reverse an integer entered by the user. This problem is solved using while loop in this example.

Example: Reverse an Integer


#include <stdio.h>
int main()
{
    int n, reversedNumber = 0, remainder;

    printf("Enter an integer: ");
    scanf("%d", &n);

    while(n != 0)
    {
        remainder = n%10;
        reversedNumber = reversedNumber*10 + remainder;
        n /= 10;
    }

    printf("Reversed Number = %d",reversedNumber);

    return 0;
}

Output

Enter an integer: 2345
Reversed Number = 5432

❰ Previous Next ❱


C

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website