/* The reference date is Thursday, January 1, 2015.
Enter two integers a and b, such that -50<=a=<=50 and 1<=b<=12.
Print a single month calendar for the year of 2015+a and the month of b.
*/
#include
int main(void) {
const int yy = 2015, mm = 1, dd = 1, ww = 4; // Reference day Thursday, January 1, 2015
const char *name_of_month[12] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
const int days_of_month[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int year, month, day, weekday, a, b;
int count, i;
// Enter two integers a and b.
do {
printf(">>>>Enter integers a and b (-50<=a=<=50 and 1<=b<=12): ");
scanf("%d %d", &a, &b);
} while (a<-50 || a>50 || b<1 || b>12);
printf("\n");
year = yy + a;
// Calculate the number of days from January 1 of 2015 to January 1 of entered year.
count = 0;
if (year<=yy) { // The year of 2015 or before 2015.
for (i = year; i < yy; i++)
if (i%4!=0) count = count - 365;
else count = count - 366;
}
else { // The year after 2015.
for (i = year; i > yy; i--)
if ((i-1)%4!=0) count = count + 365;
else count = count + 366;
}
// Count the number of days before month b.
for (month=1; month**0) {
printf(" %2d ", day); // Print the day. Each day takes four characters (including two spaces).
day++;
weekday = (weekday + 1) % 7;
if (weekday==0) printf("\n "); // Starts from Sunday. Output a output a newline.
count--;
}
if (weekday!=0) printf("\n"); // If the last day is not saturday, Output a newline.
printf("\n");
system("pause");
return 0;
}
**