C Exercise Example 49
Title:Comprehensive application of #if, #ifdef, and #ifndef.
Program analysis:None.
Program source code:
// Created by www.example.com on 15/11/9.
// Copyright © 2015年 Example. All rights reserved.
//
#include<stdio.h>
#define MAX
#define MAXIMUM(x,y)(x>y)?x:y
#define MINIMUM(x,y) (x>y)?y:x
int main()
{
int a=10,b=20;
#ifdef MAX
printf("更大的数字是 %d\n",MAXIMUM(a,b));
#else
printf("更小的数字是 %d\n",MINIMUM(a,b));
#endif
#ifndef MIN
printf("更小的数字是 %d\n",MINIMUM(a,b));
#else
printf("更大的数字是 %d\n",MAXIMUM(a,b));
#endif
#undef MAX
#ifdef MAX
printf("更大的数字是 %d\n",MAXIMUM(a,b));
#else
printf("更小的数字是 %d\n",MINIMUM(a,b));
#endif
#define MIN
#ifndef MIN
printf("更小的数字是 %d\n",MINIMUM(a,b));
#else
printf("更大的数字是 %d\n",MAXIMUM(a,b));
#endif
return 0;
}
The output of the above example is:
更大的数字是 20 更小的数字是 10 更小的数字是 10 更大的数字是 20other extensions