c语言 万年历!!时间:2021-03-02 01:41:56#include "stdio.h"int isleapyear(int year){ if((year%4!=0||year%100==0) && (year%400!=0) ) return 0; else return 1;}int firstdayofyear(int year){ return (year+(year-1)/4+(year-1)/400-(year-1)/100)%7;}main(){ char *monthname[13]={" ","一月份","二月份","三月份","四月份","五月份","六月份","七月份","八月份","九月份","十月份","十一月份","十二月份"}; int numday_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int firstday_month[13]; int workarray[13]; int year;char ch; int i,m,n; do { system("cls"); //清屏效果 printf("/n");printf("/n"); printf(" 欢 迎 进 入 万 年 历 查 询 系 统/n"); printf("/n"); printf(" 请输入要查询的年份:"); scanf("%d",&year); if(isleapyear(year)) numday_month[2]=29; firstday_month[1]=firstdayofyear(year); for(i=2;i<=12;i++) firstday_month[i]=(firstday_month[i-1]+numday_month[i-1])%7; for(i=1;i<=12;i++) workarray[i]=-firstday_month[i]; printf("%34s"," "); printf("year %d/n",year);for(i=1;i<=12;i++){ printf("/n"); printf("%32s/n/n",monthname[i]); //printf("%22s"," "); printf("星期日/t星期一/t星期二/t星期三/t星期四/t星期五/t星期六/n"); for(m=1;m<=6;m++){ //printf("%18s"," "); for(n=1;n<=7;n++){ workarray[i]++; if(workarray[i]>0&&workarray[i]<=numday_month[i]) printf("%d/t",workarray[i]); else printf("/t");} printf("/n");}system("pause");} printf("/n是否要继续请按Y/y,按其它键退出系统:");scanf(" %c",&ch);}while(ch=='Y'||ch=='y');}