데블 날 만달력 드
~cpp #include <iostream> #include <climits> using namespace std; void output(int , int); int deter_date(int, int); int lastdays(int, int); int how_much_days(int, int); int main() { int year, month; while (true) { cout << "를 력 : "; cin >> year; cout << " 력 : "; cin >> month; if ( !year || !month ) break; if ( year <= 0 || year >INT_MAX || month <=0 || month>12) { cout << "못 력다." << endl; continue; } output(year, month); } return 0; } void output(int year, int month) { int days = how_much_days(year, month); int date; if (year%400 != 0) date = deter_date(year%400, month); //(?) year%400 대 year 면 러... 로? //400기로 달력 같므로 year%400로 결. else date = deter_date(400, month); cout << "====================================================" << endl << "\t\t\t\t목\t\t" << endl; for ( int j=0 ; j<date ; j++) //를 기 만 cout << "\t"; for ( int i=0 ; i<days ; i++) //1 days까 력 { if ( date > 6 ){ // 가면 cout << endl; //다로 가고 date=0; // 로 } cout << i+1 << "\t"; date++; //보때는 가 } cout << endl << "====================================================" << endl; } int deter_date(int year, int month )// 는 (0 , 6 ) { if ( month == 0 ){ year--; month = 12; } else if ( year == 1 && month == 1) return 1; // 1 1는 부 return (lastdays(year,month) + deter_date(year, month-1)) % 7;// 드 /* 난 달 며를 고 기 난달 는 면 달 무 는 다. 를 들 1 2 같 경 1 1 31고 부 므로 (31 + 1) % 7 == 4 로 목부 다. */ } int lastdays(int year, int month)//난 달 날를 { int last; switch(month) { case 3: if ( year%4 == 0) { last = 29; if ( year%400 == 0 ) last = 29;//달 if ( year%4000 == 0 ) last = 28;//달 else if ( year%100 == 0 ) last = 28;//달 } else last = 28; break; case 5: case 7: case 10: case 12: last = 30; break; case 1: case 8: case 2: last = 31; break; case 4: case 6: case 9: case 11: last = 31; break; } return last; } int how_much_days(int year, int month) { int days; switch(month)// 달 날를 { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: if ( year%4 == 0) { days = 29; if ( year%400 == 0 ) days = 29;//달경 if ( year%4000 == 0) days = 28;//달 경 else if ( year%100 == 0 ) days = 28;//달경 } else//달 경 days = 28; break; case 4: case 6: case 9: case 11: days = 30; break; } return days; }