用c语言调用函数编程,1990年1月1日是星期一 要求输入某年某月某日,输出它是星期几 5
1个回答
展开全部
这个是1984年1月1日是星期日的,你先看看,我再帮你改,最好自己能看懂
#include <stdio.h>
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);
/*上面是计算输入的日期距1984年1月1日一共经历了多少天*/
weekday = (sum-1) % 7;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
下面是修改好的,能多给些分嘛?写程序不容易,还有,好好学习,这些不难,就是多花点时间而已
#include <stdio.h>
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);
/*上面是计算输入的日期距1990年1月1日一共经历了多少天*/
weekday = (sum-1) % 7+1;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
#include <stdio.h>
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);
/*上面是计算输入的日期距1984年1月1日一共经历了多少天*/
weekday = (sum-1) % 7;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
下面是修改好的,能多给些分嘛?写程序不容易,还有,好好学习,这些不难,就是多花点时间而已
#include <stdio.h>
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);
/*上面是计算输入的日期距1990年1月1日一共经历了多少天*/
weekday = (sum-1) % 7+1;
week = yearday / 7;
printf("今天是第%d个星期,星期%d",week,weekday);
return ;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询