◈ 이 글은 강의를 위하여 제가 직접 작성한 내용입니다. 따라서 퍼가실 경우, 출처를 명확히 해주시기 바랍니다!!
◈ This ariticle was written by me for teaching. So if you want to copy this article, please clarify the source!!
◈ This ariticle was written by me for teaching. So if you want to copy this article, please clarify the source!!
#include#include using namespace std; #define MAX(x,y) ((x > y)? x : y) #define MIN(x,y) ((x < y)? x : y) int Max(int x, int y) { return ((x > y)? x : y); } int Min(int x, int y) { return ((x < y)? x : y); } void main() { // 배열에 1~100사이의 수를 랜덤하게 삽입하고, 배열의 최대,최소값을 구하시오. int randnum[100]; int counts=sizeof(randnum)/sizeof(int); srand((unsigned)time(0)); for(int i=0;i < counts;i++) { randnum[i] = rand() % 100 + 1; cout << randnum[i] << " "; } cout << endl; int max=randnum[0]; int min=randnum[0]; for(int i=1;i < counts;i++) { // if(randnum[i] > max) max = randnum[i]; // if(randnum[i] < min) min = randnum[i]; randnum[i] > max?max=randnum[i]:0; randnum[i] < min?min=randnum[i]:0; // max = (randnum[i] > max?randnum[i]:max); // min = (randnum[i] < min?randnum[i]:min); // max = MAX(randnum[i], max); // min = MIN(randnum[i], min); // max = Max(randnum[i], max); // min = Min(randnum[i], min); } cout << "최대값 :" << max << endl; cout << "최소값 :" << min << endl; }