<分区>
Possible Duplicate:
How to get the digits of a number without converting it to a string/ char array?
我在 C++ 中无法完成这项任务;我想做的是计算出用户给定的任何数字的个位数和十位数。
例如,如果数字是9775,则得到个位数为9775 % 10
,
但我无法找到十位数。
标签 c++
<分区>
Possible Duplicate:
How to get the digits of a number without converting it to a string/ char array?
我在 C++ 中无法完成这项任务;我想做的是计算出用户给定的任何数字的个位数和十位数。
例如,如果数字是9775,则得到个位数为9775 % 10
,
但我无法找到十位数。
最佳答案
对于非负整数 x,十位是 (x/10) % 10
。
关于c++ - 如何在C++中确定一个数的十位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12795225/