大众计算机学习网

专门提供各种电脑教程

C语言:#if #ifdef和#ifndef的综合应用

Admin | 2008-1-13 13:38:48 | 被阅次数 | 23194

  C语言#if #ifdef和#ifndef的综合应用代码如下:

  程序源代码:
  #include "stdio.h"
  #define MAX
  #define MAXIMUM(x,y) (x>y)?x:y
  #define MINIMUM(x,y) (x>y)?y:x
  void main()
  { int a=10,b=20;
  #ifdef MAX
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
  #else
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
  #endif
  #ifndef MIN
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
  #else
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
  #endif
  #undef MAX
  #ifdef MAX
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
  #else
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
  #endif
  #define MIN
  #ifndef MIN
  printf("\40: The lower one is %d\n",MINIMUM(a,b));
  #else
  printf("\40: The larger one is %d\n",MAXIMUM(a,b));
  #endif
  }