求一函数,输入日期,输出星期几

来源:百度知道 编辑:UC知道 时间:2024/05/21 14:00:50
如题,最好用c语言写的
星期一返回1,以此类推,星期日返回为7

输入日期...要写不少
#include "stdio.h"
main()
{
int day_num;
printf("enter a value between 1 and 7 : ");
scanf("%d",&day_num);

switch (day_num){
case 1: printf("The day is monday\n");
break;
case 2:printf("the day is tuesday\n");
break;
case 3:printf("the day is wednesday\n");
break;
case 4:printf("the day is thursday\n");
break;
case 5:printf("the day is friday\n");
break;
case 6:printf("the day is saturday\n");
break;
case 7:printf("the day is sunday\n");
break;
default:printf("you input number is not valid");
break;
}
}

/*
1582/10/4之后时
W=[C/4]-2C+y+[y/4]+[13*(M+1)/5]+d-1
1582/10/4之前时
w=y+[y/4]+[c/4]-2c+[13(m+1)/5]+d+2

w:星期;
c: