【C/C++】 C 拆分 int 数字

【C/C++】 C 拆分 int 数字

概述问题

在做「水仙花数」的计算开发时,遇到需要将整数每个位数拆分的需求。在此列出解决方案,仅供参考。

代码

20240507174949414-详细教学@1x
#include <stdio.h>
#include <math.h>

int main() {
       while (x > 0) {    //[int]number > 0, excute
            Cache[i] = x % 10;     //Get the latest digital
            x = x / 10;        //remove the latest digital
            //printf("%d\n", Cache[i]);
            i ++;
        }
}
    © 版权声明
    THE END
    分享和支持
    点赞13 分享
    评论 抢沙发
    头像
    留下评论,见证当下。
    提交
    头像

    昵称

    取消
    昵称表情代码快捷回复

      请登录后查看评论内容