题解 | #数字颠倒#

数字颠倒

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;
}
全部评论

相关推荐

投递恒生电子股份有限公司等公司7个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务