码迷,mamicode.com
首页 > 其他好文 > 详细

三位数反转

时间:2018-03-01 20:10:55      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:int   限制   输入   一个   class   printf   body   scan   include   

#include <stdio.h>
#include <math.h>

/**
【题目】三位数反转
输入一个三位数,分离出它的百位、十位和个位,反转后输出。
样例输入:
127
样例输出:
721
*/

int main()
{
    int n,m;
    scanf("%d",&n);

    m = (n%10) * 100 + (n/10)%10 *10 + (n/100)%10 ;

    printf("%03d\n",m); // "%03d”:输出一个数值变量,不足3位在前面补0

    return 0;
}

点评:这里250反转的结果应该是052。所以要加上上面的输出限制。

三位数反转

标签:int   限制   输入   一个   class   printf   body   scan   include   

原文地址:https://www.cnblogs.com/jiqing9006/p/8489557.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!