萬年曆 C語言版本

2021-08-14 15:00:35 字數 1066 閱讀 1378

由於萬年曆具有以下特點:

1 平年365天(52周+1天),閏年366天(52周+2天),平年2月28天,閏年2月29天。由於公元1月1日設為星期六,故3月1日為星期三。為使演算法達到最簡,故本演算法以「星期」為計算單位,且選3月1日為基月。

2 每400年整一閏,或每4年且不為百年的一閏,即凡能被400整除,或不能被100整除但能被4整除的年份為閏年。

3 每 4年(3個平年+1個閏年)共208周+5天

每百年共100*(208周+5天)-1天=5217周+5天

每400年共4*(5217周+5天)+1天(整400年閏)=20871周+0天,即每400年乙個輪迴。

#include 

int total_days = 0;//全域性變數

int month_days = 0;//全域性變數

int week_days = 0;//全域性變數

int totaldays(int year, int month)

else

}for (mon = 1; mon < month; mon++)//加上從1月至所查詢月份的總天數

else

}else

if (mon == 4 || mon == 6 || mon == 9 || mon == 11)//每月有30天的月份

else

//每月有31天的月份

}}int weekday()//判斷所查詢月份的第一天是星期幾

int monthdays(int year, int month)//判斷當月共有多少天

else

}else

if (month == 4 || month == 6 || month == 9 || month == 11)

else

}void print()//列印資訊

int k;

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

else

total_days++;

}printf("\n\n");

}int main()

萬年曆 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...