C语言。求指教!请帮我写一下程序注释解释一下。已知公元1年1月1日是星期一。计算输入的年月日是星期几。

#include<stdio.h>voidmain(){longyear,month,day;longtotalday;intweek;intmonthday[12]={... #include <stdio.h>
void main()
{
long year,month,day;
long totalday;
int week;
int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,334};//什么意思?
int monthdayLeap[12]={0,31,60,91,121,152,182,213,244,274,305,335};//什么意思?
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]);
}
展开
 我来答
御含灵9r
2012-11-27 · TA获得超过4157个赞
知道大有可为答主
回答量:3007
采纳率:0%
帮助的人:2692万
展开全部
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]);
}
Google也知道
2012-11-27 · TA获得超过755个赞
知道小有建树答主
回答量:422
采纳率:0%
帮助的人:194万
展开全部
#include <stdio.h>
void main()
{
long year,month,day;
long totalday;
int week;
int monthday[12]={0,31,59,90,120,151,181,212,243,273,304,334};//monthday数组初始化
int monthdayLeap[12]={0,31,60,91,121,152,182,213,244,274,305,335};//monthdayLeap数组初始化
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]);//这个就是输出星期几的地方
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式