各位大虾帮帮忙了~~~~~
``
已知道1900年1月1日是星期一,请输入一具体的日期,如何判断此日期是星期几?请利用C语言来进行编程
答案:2 悬赏:0 手机版
解决时间 2021-03-02 02:11
- 提问者网友:趣果有间
- 2021-03-01 16:51
最佳答案
- 五星知识达人网友:零点过十分
- 2021-03-01 17:18
我的思路 先计算输入的日期与1900.1.1相差的天数 然后对7求余
全部回答
- 1楼网友:空山清雨
- 2021-03-01 18:28
这个是1984年1月1日是星期日的,你先看看,我再帮你改,最好自己能看懂
#include
void main()
{
int year,month,day;
int tempmonth,yearday;
int week,weekday;
unsigned int sum=0;
int tag=0;
printf("输入年、月、日:\n");
scanf("%d %d %d",&year,&month,&day);
tag =( year - 1980 )/4;
sum=(year-1984)*365 + tag;
tempmonth = month - 1;
yearday = 0;
switch(tempmonth)
{
case 12:yearday+=31;
case 11:yearday+=30;
case 10:yearday+=31;
case 9:yearday+=30;
case 8:yearday+=31;
case 7:yearday+=31;
case 6:yearday+=30;
case 5:yearday+=31;
case 4:yearday+=30;
case 3:yearday+=31;
case 2:yearday+=28;
case 1:yearday+=31;
}
yearday = yearday+day;
if ((year-1984)%4==0 && month > 2)
{
yearday+=1;
}
sum=sum+yearday;
if (year==1984)
{
sum-=1;
}
printf("距1984年1月1日一共有%d天\n",sum);
weekday = (sum-1) % 7;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
下面是修改好的,能多给些分嘛?写程序不容易,还有,好好学习,这些不难,就是多花点时间而已
#include
void main()
{
int year,month,day;
int tempmonth,yearday;
int week,weekday;
int sum=0;
int tag=0;
printf("输入年、月、日:\n");
scanf("%d %d %d",&year,&month,&day);
tag =( year - 1988 )/4;
printf("tag=%d\n",tag);
sum=(year-1990)*365 + tag;
tempmonth = month - 1;
yearday = 0;
switch(tempmonth)
{
case 12:yearday+=31;
case 11:yearday+=30;
case 10:yearday+=31;
case 9:yearday+=30;
case 8:yearday+=31;
case 7:yearday+=31;
case 6:yearday+=30;
case 5:yearday+=31;
case 4:yearday+=30;
case 3:yearday+=31;
case 2:yearday+=28;
case 1:yearday+=31;
}
yearday = yearday+day;
if ((year-1988)%4==0 && month > 2)
{
yearday+=1;
}
sum=sum+yearday;
printf("sum=%d\n",sum);
printf("距1990年1月1日一共有%d天\n",sum);
weekday = (sum-1) % 7+1;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯