C语言完整代码星期几换算
时间: 2023-12-03 20:41:18 浏览: 191
以下是C语言完整代码,用于将给定日期转换为星期几:
```c
#include <stdio.h>
#include <stdlib.h>
int main()
{
int year, month, day;
printf("请输入日期(格式:年-月-日):"); scanf("%d-%d-%d", &year, &month, &day);
if (month == 1 || month == 2) {
month += 12;
year--;
}
int week = (day + 2 * month + 3 * (month + 1) / 5 + year + year / 4 - year / 100 + year / 400) % 7;
switch (week) {
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;
}
```
阅读全文