Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to reverse decimal numbers more efficient.

#include <stdio.h>

int main()
{

while(1)
 {
 int a,result;
  
 scanf("%d",&a);
  
 result=(a%10*10)+(a/10);

 printf("%d
",result);

 }
}

Of course this will only work with 2 decimal numbers.

But I am trying to find out how I can reverse more numbers in an efficient way ( less code)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

Sorry I need to be more specific. LESS CODE –

Ugly, but short code to "reverse" a number.

int main(){int c=getchar();if(isdigit(c))main();putchar(c);}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...