基於C語言的萬年曆

2021-07-09 06:39:04 字數 3305 閱讀 2364

大一剛學幾個月c語言後寫了兩天的課程設計,儘管現在看來寫的有些稚氣,風格凌亂,但也看得出用心。留住做個回念。

#include 

#include

#include

#include

int judge(int year) //判斷該年是不是閏年

int weekday(int year) //判斷該年的1月1號是星期幾

int monthdays(int year,int i) //判斷乙個月多少天

return(monthday);

}int main()

while(a!=1 && a!=2 && a!=3);

//執行1模式

if(a==1)

while(year<=1);

system("cls");

s=judge(year);

if (s==1)

printf("%d 年為閏年,該年有366天,下面是該年的日期表:\n",year);

else

printf("%d 年為平年,該年有365天,下面是該年的日期表:\n",year);

printf("\n");

firstday=weekday(year);

for(i=1;i<=12;i++) //i代表月份

for(k=1;k<=monthday;k++)

else

setconsoletextattribute(handle, foreground_intensity | foreground_red | foreground_green | foreground_blue);//變成白色

if((k+firstday)%7==0)

printf("\n");

} firstday=(firstday+monthday)%7; //下個月份的1號星期幾

printf("\n");

printf("\n");

} }//執行2模式,內容其實和模式1是一樣的,這裡只是把不是指定的月份對應的月曆清空,剩下指定月份年的日曆

if(a==2)

while(year<=1||year>9999||month<1||month>13||day!=0);

system("cls");

s=judge(year);

if (s==1)

printf("%d 年為閏年,該年有366天,下面是%d年%d月的日期表:\n",year,month);

else

printf("%d 年為平年,該年有365天,下面是%d年%d月的日期表:\n",year,month);

printf("\n");

firstday=weekday(year);

for(i=1;i<13;i++) //i代表月份

for(k=1;k<=monthday;k++)

else

setconsoletextattribute(handle, foreground_intensity | foreground_red | foreground_green | foreground_blue);//變成白色

if((k+firstday)%7==0)

printf("\n");

}firstday=(firstday+monthday)%7; //下個月份的1號星期幾

printf("\n");

printf("\n");

if(i==month)

break;}}

printf("\n");

setconsoletextattribute(handle, foreground_intensity | foreground_green | foreground_blue);//變成白色

if (s==1)

printf("%d 年為閏年,該年有366天,以上是 %d年%d月 的日期表:\n",year,year,month);

else

printf("%d 年為平年,該年有365天,以上是 %d年%d月 的日期表:\n",year,year,month);

}//以下是3模式,內容其實和模式1是一樣的,這裡只是把不是指定的月份對應的月曆清空,剩下指定月份年的日曆,並且如果當期滿足輸入的天時,變為高亮色

if(a==3)

while(year<=1||month<1||month>13||day==0);

system("cls");

s=judge(year);

if (s==1)

printf("%d 年為閏年,該年有366天,下面是%d年%d月的日期表:\n",year,month);

else

printf("%d 年為平年,該年有365天,下面是%d年%d月的日期表:\n",year,month);

printf("\n");

firstday=weekday(year);

for(i=1;i<13;i++) //i代表月份

for(k=1;k<=monthday;k++)

else

} else

else

}setconsoletextattribute(handle, foreground_intensity | foreground_red | foreground_green | foreground_blue); //變成白色

if((k+firstday)%7==0)

printf("\n");

}firstday=(firstday+monthday)%7; //下個月份的1號星期幾

printf("\n");

printf("\n");

if(i==month)

break;}}

printf("\n");

setconsoletextattribute(handle, foreground_intensity | foreground_green | foreground_blue);//變成白色

if (s==1)

printf("%d 年為閏年,該年有366天,以上是 %d年%d月%d日 對應的日期表,這一天是星期 %d \n",year,year,month,day,whichday);

else

printf("%d 年為平年,該年有365天,以上是 %d年%d月%d日 對應的日期表,這一天是星期 %d \n",year,year,month,day,whichday);

}return

0;}

2023年3月

萬年曆 C語言

顯示效果 大概步驟 1.顯示主介面 void showmenu char temp 10 2.判斷是否為閏年 bool isleap int year 3.計算總天數 int daysum int year,int month 4.顯示日曆 showcalendar int sum,int year...

C語言列印萬年曆

date.h檔案如下 列印萬年曆從1900年起 ifndef date h define date h include define out of year 1 是否是閏年 bool isleap int year 從year到1900年間閏年個數 int leapyearnum int year ...

C語言編寫萬年曆

上一次的萬年曆在後來的測試發現當1號是週日時,無法正確輸出,後來加了語句 if week 0 week 7 並且在確定當前日期到1900年1月1日的方法進行改進,不在採用for迴圈來遍歷1900年到當前年份之間閏年的個數,而是直接用 year 1900 4的方法。這個程式經過了1900,1904,1...