逻辑检查数字是否可以被3整除? [英] Logic to check the number is divisible by 3 or not?
本文介绍了逻辑检查数字是否可以被3整除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不使用%,/或*,我必须找到编号.可以被3整除吗?
without using %, / or * , I have to find the no. is divisible by 3 or not?
可能是面试问题.
谢谢.
推荐答案
减去3直到您选择其中一个
Subtract 3 until you either
点击0-数字可被3(或)整除
hit 0 - number was divisible by 3 (or)
获取小于0的数字-数字不可除
get a number less than 0 - number wasn't divisible
if (number > 0)
{
while (number > 0)
{
number -= 3;
}
}
else if( number < 0)
{
while number < 0:
number += 3
}
return number == 0
这篇关于逻辑检查数字是否可以被3整除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文