#include <stdio.h>
#include <string.h>
// 1. 피실험자 데이터를 저장할 구조체 정의
typedef struct {
char name[20]; // 이름 (소비자 식별자)
float sleep_time; // 하루 평균 수면 시간 (시간)
float weekly_dose; // 일주일간 멜라토닌 복용량 (mg)
int drowsiness_penalty; // 낮 시간 졸음 감점 수치
float sleep_debt; // 계산된 수면 부채
float mtni_score; // 최종 멜라토닌 지수 (MTNI)
} Participant;
// 2. 수면 부채 계산 함수 (적정 수면 시간 7.5시간 기준)
float calculate_sleep_debt(float sleep_time) {
float debt = 7.5f - sleep_time;
return (debt > 0) ? debt : 0.0f; // 7.5시간 이상 자면 부채는 0
}
// 3. 멜라토닌 지수(MTNI) 계산 함수
float calculate_mtni(float weekly_dose, float sleep_debt, int drowsiness_penalty) {
return (weekly_dose * 8.0f) + (sleep_debt * 15.0f) - drowsiness_penalty;
}
int main() {
// 4. 8명의 실제 데이터 초기화 (다양한 복용 및 수면 패턴 반영)
Participant list[15] = {
{"준우", 5.5, 12.0, 5},
{"소현", 7.5, 2.0, 1},
{"도은", 5.0, 5.0, 6},
{"혜림", 8.0, 1.0, 3},
{"가은", 6.0, 3.0, 6},
{"채원", 5.0, 6.0, 7},
{"상훈", 5.0, 10.0, 4},
{"채연", 7.0, 3.0, 1},
};
int total_participants = 8;
int danger_count = 0; // 위험군 인원 체크용 변수
printf("==================== 멜라토닌 지수(MTNI) 8인 분석 결과 (기준치: 100) ====================\n\n");
printf("%-10s \t%-12s \t%-12s \t%-12s \t%-12s\n", "이름", "평균수면", "수면부채", "MTNI점수", "위험도 판정");
printf("----------------------------------------------------------------------------------------\n");
// 5. 반복문을 통해 8명의 데이터 계산 및 결과 출력
for (int i = 0; i < total_participants; i++) {
// 데이터 가공 및 함수 호출
list[i].sleep_debt = calculate_sleep_debt(list[i].sleep_time);
list[i].mtni_score = calculate_mtni(list[i].weekly_dose, list[i].sleep_debt, list[i].drowsiness_penalty);
// 결과 출력
printf("%-10s \t%-10.1f시간 \t%-10.1f시간 \t%-10.1f \t",
list[i].name, list[i].sleep_time, list[i].sleep_debt, list[i].mtni_score);
// BSI 기준치(100)에 따른 위험도 판정 및 카운트
if (list[i].mtni_score > 100.0f) {
printf("[위험] 과다복용 및 부작용 주의!\n");
danger_count++;
} else {
printf("[안전] 정상 범위\n");
}
}
// 6. 전체 요약 통계 출력
printf("----------------------------------------------------------------------------------------\n");
printf("[종합 통계] 총 피실험자: %d명 | 위험군(100 초과): %d명 | 안전군: %d명\n",
total_participants, danger_count, total_participants - danger_count);
printf("========================================================================================\n");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: