题解 | 反向输出一个四位数

反向输出一个四位数

https://www.nowcoder.com/practice/1f7c1d67446e4361bf4af67c08e0b8b0

#include <stdio.h>

int main(void) {
    
    int n = 0;
    scanf("%d", &n);

    //获取个位数
    int digit = n % 10;

    //获取十位数
    int ten = (n - digit) / 10 % 10;

    //获取百位
    int hundred = (n - digit - 10 * ten) / 100 % 10;

    //获取千位
    int thousand = (n - digit - 10 * ten - 100 * hundred) / 1000 % 10;

    printf("%d%d%d%d\n", digit, ten, hundred, thousand);

    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务