好的,以下是针对你的三个问题的C语言代码实现:
1.输入一个年份,输出是在屏暮上显示该年的日历:
```c
#include <stdio.h>
int main() {
int year, month, day, week, daysInMonth, i, j, k;
int calendar[12][6][7] = {0}; // 存储日历信息的数组,第一维代表月份,第二维代表每个月份的行数,第三维代表每个月份的列数
int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 存储每个月份的天数,2月份默认为28天,闰年会在后面判断
// 输入年份
printf("请输入年份(1940-2040):");
scanf("%d", &year);
// 判断年份是否合法
if (year < 1940 || year > 2040) {
printf("输入的年份不合法!\n");
return 0;
}
// 判断是否为闰年,并修改2月份的天数
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
monthDays[1] = 29;
}
// 计算该年份1月1日是星期几
week = (year + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7;
// 循环计算每个月份的日历信息
for (i = 0; i < 12; i++) {
daysInMonth = monthDays[i];
// 循环计算每个月份的日历信息,存储到二维数组中
for (j = 0, k = week; j < daysInMonth; j++, k++) {
calendar[i][k / 7][k % 7] = j + 1;
}
// 更新下一个月份的起始位置
week = (week + daysInMonth) % 7;
}
// 输出整个年份的日历
printf("\n\t\t%d 年\n", year);
for (i = 0; i < 12; i++) {
printf("\n\t\t%d 月\n", i + 1);
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n"); // 输出日历表头
for (j = 0; j < 6; j++) {
for (k = 0; k < 7; k++) {
if (calendar[i][j][k] == 0) {
printf(" \t"); // 输出空格
} else {
printf("%d\t", calendar[i][j][k]); // 输出日期
}
}
printf("\n");
}
}
return 0;
}
```
2.输入年月,输出该月的日历:
```c
#include <stdio.h>
int main() {
int year, month, day, week, daysInMonth, i, j, k;
int calendar[6][7] = {0}; // 存储日历信息的数组,第一维代表每个月份的行数,第二维代表每个月份的列数
int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 存储每个月份的天数,2月份默认为28天,闰年会在后面判断
// 输入年份和月份
printf("请输入年份:");
scanf("%d", &year);
printf("请输入月份:");
scanf("%d", &month);
// 判断年份和月份是否合法
if (year < 1940 || year > 2040 || month < 1 || month > 12) {
printf("输入的年份或月份不合法!\n");
return 0;
}
// 判断是否为闰年,并修改2月份的天数
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
monthDays[1] = 29;
}
// 计算该月份1日是星期几
week = (year + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400) % 7;
for (i = 0, k = week; i < monthDays[month - 1]; i++, k++) {
calendar[k / 7][k % 7] = i + 1; // 存储每一天的日历信息
}
// 输出该月份的日历
printf("\n\t\t%d 年 %d 月\n", year, month);
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n"); // 输出日历表头
for (i = 0; i < 6; i++) {
for (j = 0; j < 7; j++) {
if (calendar[i][j] == 0) {
printf(" \t"); // 输出空格
} else {
printf("%d\t", calendar[i][j]); // 输出日期
}
}
printf("\n");
}
return 0;
}
```
3.输入年月日,输出距今天还有多少天,星期几,是否是公历节日:
```c
#include <stdio.h>
int main() {
int year, month, day, i, daysInYear, daysInMonth, daysInDay;
int daysInMonthOfYear[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; // 存储每个月份从1月1日开始的天数
char *weekdays[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; // 存储星期几的字符串
char *holidays[] = {"New Year's Day", "Valentine's Day", "International Women's Day", "April Fools' Day", "Labour Day", "Children's Day", "Dragon Boat Festival",
"Mid-Autumn Festival", "National Day", "Halloween", "Thanksgiving Day", "Christmas Day"}; // 存储公历节日的字符串
int holidayDates[] = {1, 14, 8, 1, 1, 1, 5, 15, 1, 31, 4, 25}; // 存储公历节日的日期
int holidayMonths[] = {1, 2, 3, 4, 5, 6, 6, 9, 10, 10, 11, 12}; // 存储公历节日的月份
// 输入年份、月份和日期
printf("请输入年份:");
scanf("%d", &year);
printf("请输入月份:");
scanf("%d", &month);
printf("请输入日期:");
scanf("%d", &day);
// 判断年份和月份是否合法
if (year < 1940 || year > 2040 || month < 1 || month > 12 || day < 1 || day > 31) {
printf("输入的年份或月份或日期不合法!\n");
return 0;
}
// 判断是否为闰年,并修改2月份的天数
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
daysInYear = 366;
if (month > 2) {
daysInDay = 1; // 如果是闰年且输入日期在3月1日之后,则当天是今年的第61天
}
} else {
daysInYear = 365;
}
// 计算距离今天还有多少天
daysInMonth = daysInMonthOfYear[month - 1] + day - 1 + daysInDay;
if (month > 2 && daysInYear == 366) {
daysInMonth += 1; // 如果是闰年且输入日期在3月1日之后,那么今年的第61天要算上
}
printf("距离今天还有 %d 天\n", daysInYear - daysInMonth);
// 计算星期几
printf("今天是 %s\n", weekdays[(daysInYear - daysInMonth + 6) % 7]);
// 查询是否是公历节日
for (i = 0; i < 12; i++) {
if (holidayDates[i] == day && holidayMonths[i] == month) {
printf("今天是公历节日:%s\n", holidays[i]);
break;
}
}
return 0;
}
```