devc++输出万年历
时间: 2023-11-24 21:51:22 浏览: 93
VC++万年历
以下是使用Dev-C++输出万年历的代码示例:
```c
#include <stdio.h>
int main()
{
int year, month, day, i, j, days;
int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char week[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
printf("Please enter the year: ");
scanf("%d", &year);
printf("Please enter the month: ");
scanf("%d", &month);
// 判断是否为闰年
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
monthDays[1] = 29;
}
// 计算当月第一天是星期几
day = 1;
for (i = 1; i < month; i++) {
day += monthDays[i - 1];
}
j = (year - 1) + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 + day;
j %= 7;
// 输出日历表头
printf("\n %d-%02d\n", year, month);
printf("--------------------\n");
for (i = 0; i < 7; i++) {
printf("%s ", week[i]);
}
printf("\n");
// 输出日历内容
days = monthDays[month - 1];
for (i = 0; i < j; i++) {
printf(" ");
}
for (i = 1; i <= days; i++) {
printf("%3d ", i);
if ((i + j) % 7 == 0) {
printf("\n");
}
}
printf("\n");
return 0;
}
```
阅读全文