以下宏作用分别为,求两个数最小值,三个数最小值,打印一个数组和打印一个数组元素总和。
#include "stdio.h"
#define MINI2(x, y) ((x) <= (y)) ? (x) : (y)
#define MINI3(x, y, z) MINI2(MINI2(x, y), z)
#define PRINTARRAY(arr, size) int i = 0; for (; i < (size); i++) printf("%d\n", arr[i]);
#define SUMARRAY(arr, size) int i = 0, sum = 0; for (; i < (size); i++) sum += arr[i]; \
printf("%d\n", sum);
#define DEBUG 3
int main(int argc, char const *argv[])
{
#if DEBUG == 1
int x, y, z;
scanf("%d %d", &x, &y);
printf("%d\n", MINI2(x, y));
scanf("%d %d %d", &x, &y, &z);
printf("%d\n", MINI3(x, y, z));
#elif DEBUG == 2
int arr[5] = {1, 2, 3, 4, 5};
PRINTARRAY(arr, 5)
#elif DEBUG == 3
int arr[5] = {1, 2, 3, 4, 5};
SUMARRAY(arr, 5)
#endif
return 0;
}