#define MAX(A,B) ((A)>(B)?(A):(B))
#define MAX(A,B,C) ((A)>(B)?(A):(B))>C?((A)>(B)?(A):(B)):C
#define MAX(A,B,C,D) ((A)>(B)?(A):(B))>((C)>(D)?(C):(D))?((A)>(B)?(A):(B)):((C)>(D)?(C):(D))
测试代码如下:
#include <iostream>
using namespace std;
#define MAX2(A,B) ((A)>(B)?(A):(B))
#define MAX3(A,B,C) ((A)>(B)?(A):(B))>C?((A)>(B)?(A):(B)):C
#define MAX4(A,B,C,D) ((A)>(B)?(A):(B))>((C)>(D)?(C):(D))?((A)>(B)?(A):(B)):((C)>(D)?(C):(D))
void main()
{
int max2 = MAX2(1,2);
int max3 = MAX3(1,2,3);
int max4 = MAX4(1,2,3,4);
cout << max2 << endl;
cout << max3 << endl;
cout << max4 << endl;
}