int ref = x; int y; int rev =0; if(x<0) return 0; if(x==0) return 1; if(x>INT_MIN || x<INT_MAX) { while(x) { y=x%10; x=x/10; if(rev > INT_MAX/10 || (rev == INT_MAX / 10 && y>7)) return 0; if(rev < INT_MIN/10 || (rev == INT_MIN / 10 && y<-8)) return 0; rev=rev*10+y; } } cout <<rev<<"\n"; if(ref == rev) return rev; else return 0;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter