Monday, August 4, 2014

Reverse a number

Write a program to to reverse a number.

SOLUTION:

 /*
 * Program for Reversing a number
 * Written by Shaeed Khan. 
 * Date: 04 Aug 2014
 * Version- 1.0 
 * Language: C
 */

#include < stdio.h >  
#include < stdlib.h > 

void main()
{
 int x,n;
 printf("Enter a number :");
 scanf("%d",&n);
 x=reverse(n);
 printf("%d",x);
}

int reverse(int n)
{
 int s=0;
 while(n>0)
 {
  s=s *10 + n%10;
  n=n/10;
 }
 return s;
}

No comments:

Post a Comment