得如何驗證碼爲5多的5檢查
bool isMultipleof5(int n)
{
/* If n is a multiple of 5 then we make sure that last
digit of n is 0 */
if ((n&1) == 1)
n <<= 1;
float x = n;
x = ((int)(x*0.1))*10;
/* If last digit of n is 0 then n will be equal to (int)x */
if ((int)x == n)
return true;
return false;
}
if((n%5)== 0)如何返回true;返回false;'? – sharptooth 2012-01-27 14:15:22
或'return(n%5)== 0;' – Mat 2012-01-27 14:16:12
爲什麼最後一位數字是'0'? '5'是'5'的倍數,二進制是'101'。 '105'也是'5'的倍數,它是二進制的'1101001'。 – sharptooth 2012-01-27 14:16:36