Sunday, January 3, 2010

Reversing a number

int n=12345,m=0;
cout<<"Orginal No:"< 
while(n>0)
m *= 10
m += n%10
n /= 10;
} 
cout<<"\nRevesed No:"<
 
 
 
Recursive function 
int reverse_num(int n,int m)

{

    if(n==0)

        return m; //base (exit condition)

    m*=10;

    m+=n%10;

    return reverse_num(n/10,m); //recursive call

} 

0 comments:

Post a Comment