Reverse a Number

Spread the love

Problem Statement

Write a program to reverse a number.

Code

// Reverse a number

#include <stdio.h>
int main()
{
   int n, reverse=0, rem; 
printf("Enter the number: ");
   scanf("%d", &n);    
   while(n!=0)    
   {    
     rem=n%10;    
     reverse=reverse*10+rem;    
     n/=10;    
   }    
   printf("%d",reverse);

/* Tech - https://tech.arclasses.net */
    return 0;
}

Sample Input

1234

Sample Output

4321

Read more…


Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *