请定义一个宏,比较两个数a、b的大小,不能使用大于、小于和if语句。
答:
使用两个数的差值和与运算来判断这两个数的大小。
答:
使用两个数的差值和与运算来判断这两个数的大小。
#include <cstdlib>
#include <iostream>
using namespace std;
#define MAX(a,b) (((long)(a-b))&0x80000000)?b:a;
int main(int argc, char *argv[])
{
int a=1000,b=1022;
int maxValue=MAX(a,b);
cout<<"the max value is "<<maxValue<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}