如何将int拆分为数字? [英] How do I split an int into its digits?

查看:207
本文介绍了如何将int拆分为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将c ++中的int拆分为单个数字?例如,我想将23分为2和3。

How can I split an int in c++ to its single numbers? For example, I'd like to split 23 to 2 and 3.

推荐答案

给出数字12345:

5 12345%10

4 12345/10%10

3 12345/100%10

2 12345 / 1000%10

1 12345/10000%10

5 is 12345 % 10
4 is 12345 / 10 % 10
3 is 12345 / 100 % 10
2 is 12345 / 1000 % 10
1 is 12345 / 10000 % 10

我不会提供完整的代码,因为这肯定看起来像是家庭作业,但我确定您已经掌握了模式。

I won't provide a complete code as this surely looks like homework, but I'm sure you get the pattern.

这篇关于如何将int拆分为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆