C语言.求指教!已知公元1年1月1日是星期一.计算输入的年月日是星期几.#include void main(){long year,month,day;long totalday;int week;int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,int monthdayLeap[12]={0,31,60,91,121,
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 01:15:11
C语言.求指教!已知公元1年1月1日是星期一.计算输入的年月日是星期几.#include void main(){long year,month,day;long totalday;int week;int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,int monthdayLeap[12]={0,31,60,91,121,
C语言.求指教!已知公元1年1月1日是星期一.计算输入的年月日是星期几.
#include
void main()
{
long year,month,day;
long totalday;
int week;
int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,
int monthdayLeap[12]={0,31,60,91,121,152,182,213,244,274,305,
char * weekname[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};//这个指针是什么意思?
printf("Please input Year Month Day:");
scanf("%ld %ld %ld",&year,&month,&day);
totalday=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;//这条语句是什么意思?
if((year%4==0)&&(year%100!=0)||(year%400==0))
totalday+=monthdayLeap[month-1];
else
totalday+=monthday[month-1];
totalday+=day;
week=totalday%7;//知道了week,怎么输出星期几?
printf("%ld,%s\n",totalday,weekname[week]);
}
C语言.求指教!已知公元1年1月1日是星期一.计算输入的年月日是星期几.#include void main(){long year,month,day;long totalday;int week;int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,int monthdayLeap[12]={0,31,60,91,121,
int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,334};//平常年份到该月1号之前共有多少天,1月1号之前0天 3月1号之前59天
int monthdayLeap[12]={0,31,60,91,121,152,182,213,244,274,305,335};//闰年到x月1号多少天
char * weekname[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};//是指针的数组,不是指针,数组的每个成员是一个指针指向星期几的英语,用于最后的输出
printf("Please input Year Month Day:");
scanf("%ld %ld %ld",&year,&month,&day);
totalday=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;//计算迄今为止每年365天一共多少天加上闰年的个数(每个闰年增加天,被4整除是闰年 被100整除的不是 被400整除的是)
if((year%4==0)&&(year%100!=0)||(year%400==0))
totalday+=monthdayLeap[month-1];
else
totalday+=monthday[month-1];
totalday+=day;
week=totalday%7;//总共的天数对7求模得到余数
printf("%ld,%s\n",totalday,weekname[week]);
}