C Program to Reverse a Number - C program to Reverse the Digits of a Number



 c program to reverse the digits of a number

Learn C - C tutorial - c program to reverse the digits of a number - C examples - C programs

C Program to Reverse a Number

  • This is the program for reverse the given input integer.
  • If a user will enter 123 as input then 321 will be printed as output.
  • To reverse large numbers use long data type, if you still have large numbers then use a string or other data structure.

Sample Code

#include<stdio.h>
int main()
{
    int number=97892529;
    int r;
    int reverse = 0;
    printf("Number:97892529");
    while(number)
    {
        r=number%10;
        reverse=reverse*10+r;
        number=number/10;
    }
    printf("\nReversed number is : %d",reverse);
    return 0;
}

Output

Number:97892529
Reversed number is : 92529879


View More Quick Examples


Related Searches to C Program to Reverse a Number - C program to Reverse the Digits of a Number