#include
// calendar.c written by martin for 59.102 July 2010
// verson 1.2
int leapyear(int year) {
// is year a leap year?
// the rule for leap years is that a year is a leap year if it
// is divisible by four but not by 100 or it is divisible by 400
if(((year%4==0) && (year%100!=0)) || (year%400==0)) {
return 1;
} else {
return 0;
}
}
int daysinmonth(int year, int month) {
// Thirty days hath September, April, June, and November;
// All the rest have thirty-one
// Excepting February alone: Which hath but twenty-eight, in fine,
// Till leap year gives it twenty-nine.
int monthlengths[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if ((month==1) && leapyear(year)==1) {
return 29;
} else {
return monthlengths[month];
}
}
int printmonth(int year, int month, int firstday) {
// print a complete month, firstday is
// the number for the first day of the month (0 is sunday)
char monthnames[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int i;
printf("\n %s\n",monthnames[month]);
printf(" Sun Mon Tue Wed Thu Fri Sat\n");
for(i=0;i