algorithm - C - reverse a number -


i coding in c on linux, , need reverse number. (eg: 12345 turn 54321), going convert string using itoa , reverse that, it's lot easier string manipulation, turns out itoa non standard , isn't included in gcc. there way of doing binary rotation style thing on decimal numbers , if not approach should take?

int n; scanf("%d",&n); int rev=0,rem; while(n>0) {     rem=n%10; //take out remainder .. becomes 5 12345     rev=rev*10+rem; //multiply current number 10 , add remainder.     n=n/10; //divide number. becomes 1234. } printf("%d",rev); 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -