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

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

c - Is there a more efficient way to reverse decimal numbers?

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...