Skip to content

Instantly share code, notes, and snippets.

@nalin-adh
Created November 10, 2015 17:03
Show Gist options
  • Save nalin-adh/eb178fa0cc221442ec11 to your computer and use it in GitHub Desktop.
Save nalin-adh/eb178fa0cc221442ec11 to your computer and use it in GitHub Desktop.
A C++ program to reverse a number using function.
#include<iostream>
#include<conio.h>
using namespace std;
int rev(int n);
int main()
{
int x;
cout<<"Enter any number to reverse it : ";cin>>x;
cout<<"\nThe reverse form of "<<x<<" is "<<rev(x);
getch();
return(0);
}
int rev(int n)
{ int num;
while(n!=0)
{
int r=n%10;
num=num*10+r;
n=n/10;
}
return(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment