检查数字是整除24 [英] Check if number is divisible by 24

查看:201
本文介绍了检查数字是整除24的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出了一个IF函数,它确实否则函数没有,同样的逻辑不过,我想看看输出是一个完美的数字,将看到该变量是整除24,如果是则,例如,如果我们这样做是24/24将获得1,这是一个完美的数字。如果我们这样做25/24那么它会得到1.041这是不是一个完美的数字,当它达到48,这将是48/24,将得到2,这是一个完美的数字下一个完美的数字会来的。


解决方案

使用模运算符:

 如果(编号%24 == 0)
{
$ ... b $ b}




%运算符除以它的第一个之后,计算剩余它的第二个操作数
。所有的数字类型已预定义其余运营商




几乎是它返回一个除法的余数:25%4 = 1,因为25装配在24一次,你有1左右。当数字完全适合你会得到一个返回0,并在你的例子是你怎么知道,如果一个数字是24整除,否则返回值将大于0。


I'd like to put up a if function, that will see if the variable is dividable by 24, if it's then it does the function else not, same logic however, I want to see if the output is a perfect number, e.g if we do 24/24 that will get 1, that's a perfect number. If we do 25/24 then it'll get 1.041 which is not a perfect number, the next perfect number will come when it reaches 48 that will be 48/24 which will get 2 that's a perfect number.

解决方案

Use the Modulus operator:

if (number % 24 == 0)
{
   ...
}

The % operator computes the remainder after dividing its first operand by its second. All numeric types have predefined remainder operators.

Pretty much it returns the remainder of a division: 25 % 4 = 1 because 25 fits in 24 once, and you have 1 left. When the number fits perfectly you will get a 0 returned, and in your example that is how you know if a number is divisible by 24, otherwise the returned value will be greater than 0.

这篇关于检查数字是整除24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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