Reverse of number in C

Source code :

#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:1234
Reversed Number:4321

Algorithm :

  1. Enter the required variables
  2. Use the formula of reverse while(n != 0) { remainder = n%10; reversedNumber = reversedNumber*10 + remainder; n /= 10; }
  3. Run the program
  4. Print the result

Output :


                

Comments :