万年历
//万年历
//1年1月1日 周日
//也可使用给定的日子 见黑色星期五 打印日历
#include <stdio.h>
int months[2][13] = {{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, //非闰年的12个月{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } //闰年的12个月
};
int isLeap(int year);
int main()
{int years, week, days;printf("year: ");scanf("%d", &years);for(int i = 1; i < years; i++){if(isLeap(i))days += 366;elsedays += 365;}int n = 1, m = 0;for(int i = 1; i <= 12; i++){week = (days + n - 1) % 7;printf("%d", week);printf("************************\n");printf("Sun Mon Tue Wed Thu Fri Sat\n");for(int k = 0; k < week; k++)printf(" "); //确定每月的第一天是星期几,比如说是星期三,星期日星期一星期二那里 就全是空格for(int j=1; j<= months[isLeap(i)][i]; j++){ printf("%-4d", j); //输出每个月的日期week++;if(week % 7 == 0)printf("\n"); //一周是7天,所以日期每七天换一次行}n =n + months[isLeap(years)][i];printf("\n");} return 0;
}
int isLeap(int year) //判断是否为闰年
{return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}
万年历
//万年历
//1年1月1日 周日
//也可使用给定的日子 见黑色星期五 打印日历
#include <stdio.h>
int months[2][13] = {{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, //非闰年的12个月{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } //闰年的12个月
};
int isLeap(int year);
int main()
{int years, week, days;printf("year: ");scanf("%d", &years);for(int i = 1; i < years; i++){if(isLeap(i))days += 366;elsedays += 365;}int n = 1, m = 0;for(int i = 1; i <= 12; i++){week = (days + n - 1) % 7;printf("%d", week);printf("************************\n");printf("Sun Mon Tue Wed Thu Fri Sat\n");for(int k = 0; k < week; k++)printf(" "); //确定每月的第一天是星期几,比如说是星期三,星期日星期一星期二那里 就全是空格for(int j=1; j<= months[isLeap(i)][i]; j++){ printf("%-4d", j); //输出每个月的日期week++;if(week % 7 == 0)printf("\n"); //一周是7天,所以日期每七天换一次行}n =n + months[isLeap(years)][i];printf("\n");} return 0;
}
int isLeap(int year) //判断是否为闰年
{return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
}