蔡勒公式计算星期几 c语言
时间: 2023-05-22 17:04:38 浏览: 119
可以使用蔡勒公式计算星期几的C语言代码如下:
```
#include <stdio.h>
int main() {
int year, month, day;
printf("请输入要计算的年份(四位数字):");
scanf("%d", &year);
printf("请输入要计算的月份(1-12):");
scanf("%d", &month);
printf("请输入要计算的日期(1-31):");
scanf("%d", &day);
//1月和2月看作上一年的13月和14月
if (month == 1 || month == 2) {
month += 12;
year--;
}
int century = year / 100;
int yearInCentury = year % 100;
//蔡勒公式
int weekDay = (day + (26 * (month + 1)) / 10 + yearInCentury + yearInCentury / 4 + century / 4 + 5 * century) % 7;
switch (weekDay) {
case 0:
printf("该日期是星期天\n");
break;
case 1:
printf("该日期是星期一\n");
break;
case 2:
printf("该日期是星期二\n");
break;
case 3:
printf("该日期是星期三\n");
break;
case 4:
printf("该日期是星期四\n");
break;
case 5:
printf("该日期是星期五\n");
break;
case 6:
printf("该日期是星期六\n");
break;
}
return 0;
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)