달력소스입니다 달력이 왜 이렇게 출력되는지 알려주세요
봄
질문 제목 : 이 달력에서 달력이 왜 이렇게 나오는지 알려주세요이 달력에서 달력이 왜 이렇게 출력되는지 알려주세요
예를들어서 1번을 누르면 해당년도를 입력하라고 나오는데 2011 엔터를 치면 2011년도 1월~12월까지 모두 출력이 됩니다.
그런데 어떻게해서 2011년도 1월1일이 무슨요일인지 어떻게 알죠??
그리고 2를 누루면 해당년도와 달을 누르라고 나오는데 2011 2 엔터를 누르면 2011년도 2월달이 출력이 됩니다.
그런데 어떻게해서 20111년 2월 1일이 화요일인거 어떻게 이 소느가 아는지 알려주세요 답변 부탁드립니다.
질문 내용 :
#includestdio.h
int yun_year(int year);
int start_date(int year,int month);
void print_head(int year,int month);
void print_year_calendar(int year);
void print_calendar(int year,int month);
int main(void)
{
int select,year,month;
do
{
printf(1.해당년도 달력 출력하기\n);
printf(2.해당 년도 월 달력 출력하기\n);
printf(3.프로그램 종료\n);
scanf(%d,&select);
if(select==1)
{
printf(해당 년를 입력하세요\n);
scanf(%d,&year);
print_year_calendar(year);
printf(\n\n);
}
if(select==2)
{
printf(해당 년과 월을 입력하세요\n);
scanf(%d %d,&year,&month);
print_calendar(year,month);
printf(\n\n);
}
}while(select!=3);
return 0;
}
int yun_year(int year)
{
if(year%4==0 && year%100!=0 || year%400==0)
return 29;
else
return 28;
}
int start_date(int year,int month)
{
int totaldate,i;
int months[]={31,0,31,30,31,30,31,31,30,31,30,31};
months[1]=yun_year(year);
totaldate=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;
for(i=0;imonth-1;i++)
{
totaldate+=months[i];
}
return totaldate%7;
}
void print_head(int year,int month)
{
printf(\n\n);
printf(\t[%d 년 %d 월]\n\n,year,month);
printf(\t일\t월\t화\t수\t목\t금\t토\n);
}
void print_year_calendar(int year)
{
int month;
for(month=1;month=12;month++)
{
print_calendar(year,month);
}
}
void print_calendar(int year,int month)
{
int date,startdate,i;
int count=0;
int months[]={31,0,31,30,31,30,31,31,30,31,30,31};
months[1]=yun_year(year);
print_head(year,month);
startdate=start_date(year,month);
for(i=0;i=startdate;i++)
{
printf(\t);
count++;
if(count%7==0)
printf(\n);
}
for(date=1;date=months[month-1];date++)
{
printf(\t%d,date);
count++;
if(count%7==0)
printf(\n);
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |
2695010 | C++의 STL은 왜 굳이 템플릿화 시켜서 라이브러리를 만드나요? (초보수준의 질문..) (2) | 엘보어 | 2025-05-16 |
2694958 | 로직이 변한다는 것에 대해서 궁금합니다. | 튼동 | 2025-05-16 |
2694929 | 열혈강의 25-2 두번째 문제 질문 | 지우개 | 2025-05-15 |