/*2026년 5월 31일 12주차 퀴즈 과제
202606017 나경문*/
#include <stdio.h>
#include <string.h>
void myinfo()
{
printf("202606017 나경문\n");
}
int check(char date[])
{
if(strlen(date) != 8) {
return 1; }
int year, month, day;
// 문자열 -> 정수 변환 (sscanf를 활용하여 4자리, 2자리, 2자리씩 읽어들임)
sscanf(date, "%4d%2d%2d", &year, &month, &day);
if(year<2026) {
return 2;
}
if(month < 1 || month > 12) {
return 3;
}
if(day<1 || day>31) {
return 4;
}
return 0;
}
int main() {
myinfo();
char date[20];
scanf("%s", date);
int code = check(date);
if (code == 1) {
printf("날짜 형식이 올바르지 않습니다.\n");
} else if (code == 2) {
printf("연도는 2026년 이상이어야 합니다.\n");
} else if (code == 3) {
printf("월 형식이 올바르지 않습니다.\n");
} else if (code == 4) {
printf("일 형식이 올바르지 않습니다.\n");
} else {
printf("유효한 날짜입니다.\n");
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: