Reverse a number

Program Description

In this code a given number is reversed.
For eg. Given number is 1234 then output will be 4321.

Program
/***********************************
*   Reverse a number in C
*	
*	code.cheraus.com
*
***********************************/
#include<stdio.h>
#include<conio.h>
void main()
{
   int num,t = 0;
   clrscr();
   printf("\nEnter a number : ");
   scanf("%d",&num);
 
   while (num != 0)
   {
       t = t * 10;
       t = t + num%10;
      num = num/10;
   }
 
   printf("\nReverse is : %d",num,t);
 
   getch();
}

Output
Test Case 1:

Enter a number : 1234
Reverse is : 4321

Test Case 2:

Enter a number : 9876
Reverse is : 6789

Comments
comments powered by Disqus