0

Invert int

Anyone knows how to invert a int value in c++?

30th Jan 2018, 4:25 PM
Werner Cunha
Werner Cunha - avatar
1 Odpowiedź
+ 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. }
30th Jan 2018, 7:55 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar