그래서 인터넷에 사람들이 사용하는 방법을 사용했다.
참고: http://stackoverflow.com/questions/3437404/min-and-max-in-c
#define MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
#define MIN(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
또는
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))C++ 기본 라이브러리는 min, max 함수를 제공한다.
참고: http://www.cplusplus.com/reference/algorithm/min/
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char* args[]) {
cout << min(1, 2) << endl;
cout << max(1, 2) << endl;
}
댓글 없음:
댓글 쓰기