As nothing in the question says that the result must still be an integer, why not make it an array instead? That would also elegantly solve the problem that an input that ends with a "0" would be chopped... or, even better, don't use any return value. After all, you did not ask for one.
#include <stdio.h>
voidreverse_int(intin){while(in>0){printf("%d",in%10);/* modulo 10 ... */in/=10;/* ... and move one digit. */}}/* PoC: */intmain(void){reverse_int(1234567890);return0;}
Output:
0987654321
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As nothing in the question says that the result must still be an integer, why not make it an array instead? That would also elegantly solve the problem that an input that ends with a "0" would be chopped... or, even better, don't use any return value. After all, you did not ask for one.
Output: