|
发表于 2019-6-25 22:44:33
|
显示全部楼层
本楼为最佳答案
 算了,我帮你写了
你写不出来,说明你这部分没学好,如果你喜欢编程,那有的是时间学,如果不喜欢那也就算了
这个程序真的不难
- #include <stdio.h>
- #include <stdbool.h>
- // 判断是否为闰年
- bool is_leap_year(size_t year)
- {
- if((year % 4 == 0 && year % 100 != 0 ) || ( year % 400 == 0))
- return true;
- return false;
- }
- // 给定年月日,返回星期几
- size_t get_week(size_t year, size_t month, size_t day)
- {
- day += 1;
- month += 1;
- return (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
- }
- void print_month(size_t year, size_t month)
- {
- // 平年每个月的天数
- size_t days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const char *year_name[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
- if(is_leap_year(year))
- days[1] = 29;
- printf(" %lu %s \n", year, year_name[month]);
- printf("--------------------------------------\n");
- printf(" Sun Mon Tue Wed Thu Fri Sat \n");
- printf("--------------------------------------\n");
- size_t start = get_week(year, month, 0);
- for(size_t i = 0; i < start; ++i)
- printf(" ");
- for(size_t i = 0; i < days[month]; ++i)
- {
- if((i + start) != 0 && (i + start) % 7 == 0)
- printf("\n");
- printf("%5lu", i + 1);
- }
- printf("\n");
- }
- int main(void)
- {
- size_t year;
- printf("请输入年份: ");
- scanf("%lu", &year); getchar();
- for(size_t i = 0; i < 12; ++i)
- {
- print_month(year, i);
- getchar();
- }
- return 0;
- }
复制代码 |
|