题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
#include "stdio.h" int main(void) { int num = 0; while(scanf("%d",&num) !=EOF) { char *str = (char *)calloc(15,sizeof(char)); sprintf(str,"%d",num);/*将整型数据转换成字符串*/ int j =strlen(str) - 1; int i = 0; int tmp = 0; while(i < j) /*字符串反转*/ { tmp = str[i]; str[i] = str[j]; str[j] = tmp; i++; j--; } printf("%s\n",str); /*输出*/ free(str); } return 0; }