C语言。做2012年月历。按照周格式输出。同时输出天数。不能用指针、数 ...
发布网友
发布时间:2024-01-10 23:58
我来回答
共1个回答
热心网友
时间:2024-03-06 12:56
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int year = 2012, month, day, numday, week = 7, leap, i;
if (year % 400 == 0) {
leap = 1;
} else {
if (year % 4 == 0 && year % 100 != 0) {
leap = 1;
} else {
leap = 0;
}
}
for (month = 1; month <= 12; month++) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numday = 31;
break;
case 4:
case 6:
case 9:
case 11:
numday = 30;
break;
case 2:
switch (leap) {
case 1:
numday = 29;
break;
case 0:
numday = 28;
}
}
printf("\t\t\t%d月\n", month);
printf("MON\tTUE\tWED\tTHR\tFRI\tSAT\tSUN\n");
for (day = 1; day <= numday; day++) {
if (day == 1) {
for (i = 1; i < week; i++) {
printf("\t");
}
}
printf("%d\t", day);
if (week == 7) {
week = 1;
printf("\n");
} else {
week++;
}
}
printf("\n");
}
}