Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 49

C Exercise 49

100 Classic C Language Examples 100 Classic C Language Examples

Problem:#if Comprehensive application of #ifdef and #ifndef.

**Analysis:** None.

Program source code:



//  Created by www.runoob.com on 15/11/9.

//  Copyright © 2015 Runoob Tutorial. All rights reserved.

//



#include

#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

更大的数字是 20

100 Classic C Language Examples 100 Classic C Language Examples