#define MAX_NUM_OF_DIGITS 10#define MAX_VALUE_OF_INT 0x7fffffff#define MIN_VALUE_OF_INT -0x80000000intreverse(intx){intdigits[MAX_NUM_OF_DIGITS]={0};intsign=x>0?1:0;unsignedabs=sign?x:-x;unsignedmax=sign?MAX_VALUE_OF_INT:-MIN_VALUE_OF_INT;unsignedresult=0;inti=0;intnum_digits=0;while(abs){digits[i++]=abs%10;abs/=10;}num_digits=i;for(i=0;i<num_digits&&i<9;i++)result=10*result+digits[i];if(num_digits==MAX_NUM_OF_DIGITS){/* overflow for 32-bit signed int */if(result>max/10||(result==max/10&&digits[9]>max%10))return0;elseresult=10*result+digits[i];}returnsign?result:-result;}