0
Invert int
Anyone knows how to invert a int value in c++?
1 Answer
+ 6
By invert, do you mean reverse?
Like 123 -> 321 ?
If yes, you may use :
int reverse(int n)
{
int rev;
while(n!=0)
{ rev = rev*10+(n%10); n/=10; }
return rev;
}
int main()
{
cout<<reverse(123); // Prints 321.
}