如何分割在C两位数字 [英] How to split up a two-digit number in C

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

问题描述

让我们说我有一个像21岁,我想,这样我得到的数字2和1把它分割。

要获得1,我可以做1模10.因此,基本上,最后一个数字可以通过使用模10被发现。

要送2,我可以做(21 - (1模10))/ 10。

上述技术将与任何2位数的工作。

不过,让我进一步增加了约束,mod只能用那么不能用上述方法2的幂使用。

什么就可以做什么?


解决方案

  2 == 23/10
3 == 23 - (23/10)* 10

Let's say I have a number like 21 and I want to split it up so that I get the numbers 2 and 1.

To get 1, I could do 1 mod 10. So basically, the last digit can be found out by using mod 10.

To get 2, I could do (21 - (1 mod 10))/10.

The above techniques will work with any 2-digit number.

However, let me add a further constraint, that mod can only be used with powers of 2. Then the above method can't be used.

What can be done then?

解决方案

2 == 23 / 10
3 == 23 - (23 / 10) * 10

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

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