#include <stdio.h>
#include <stdlib.h> // rand(), srand() 사용
#include <time.h> // time() 사용
#include <limits.h>
#define MAX_ELEMENTS 100
int score[MAX_ELEMENTS];
// 배열에 1~100 사이의 난수 채우기
void init_random_scores(void)
{
// 실행할 때마다 다른 난수가 생성되도록 시드 설정
srand((unsigned int)time(NULL));
for (int i = 0; i < MAX_ELEMENTS; i++) {
score[i] = (rand() % 100) + 1; // 1부터 100 사이의 값 할당
}
}
int get_max_score(int n)
{
if (n <= 0 || n > MAX_ELEMENTS) {
return INT_MIN;
}
int largest = score[0];
for (int i = 1; i < n; i++) {
if (score[i] > largest) {
largest = score[i];
}
}
return largest;
}
int main(void)
{
// 1. 난수 생성 및 배열 초기화
init_random_scores();
// 2. 최대 점수 구하기
int max_val = get_max_score(MAX_ELEMENTS);
printf("최대 점수: %d\n", max_val);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: