给出某年某月,某日,求出这天是星期几的一个c语言代码
时间: 2023-04-07 15:05:36 浏览: 159
以下是一个C语言代码,可以计算某年某月某日是星期几:
```c
#include <stdio.h>
int main()
{
int year, month, day;
printf("请输入年份:");
scanf("%d", &year);
printf("请输入月份:");
scanf("%d", &month);
printf("请输入日期:");
scanf("%d", &day);
int century = year / 100;
int year_of_century = year % 100;
int week = (day + (26 * (month + 1)) / 10 + year_of_century + year_of_century / 4 + century / 4 + 5 * century) % 7;
switch (week)
{
case 0:
printf("%d年%d月%d日是星期日\n", year, month, day);
break;
case 1:
printf("%d年%d月%d日是星期一\n", year, month, day);
break;
case 2:
printf("%d年%d月%d日是星期二\n", year, month, day);
break;
case 3:
printf("%d年%d月%d日是星期三\n", year, month, day);
break;
case 4:
printf("%d年%d月%d日是星期四\n", year, month, day);
break;
case 5:
printf("%d年%d月%d日是星期五\n", year, month, day);
break;
case 6:
printf("%d年%d月%d日是星期六\n", year, month, day);
break;
}
return 0;
}
```
阅读全文