是否有可能在没有比较的情况下找到两个整数中最大的那个?我找到了一些解决方案:
if(!(a/b)) // if a is less than b then division result will be zero.
{
cout << " b is greater than a";
}
else if (!(a-b)) // we know a is greater than or equal to b now. check whether they are equal.
{
cout << "a and b are equal";
}
else
cout << "a is greater than b";
但是 if(c) 或者 if(!c) 是与零进行比较。此外,它不适用于负数。事实上,我需要一种避免任何 if 语句的解决方案。相反,我应该使用 switch 语句和算术运算符。谢谢。