2 回答
TA贡献1776条经验 获得超12个赞
#include <stdio.h>
int day,month,year,sum,leapyes;
int leap(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))/*判断是不是闰年*/ return 1;
else
return 0;
}
int days( int y, int m, int d )
{
switch(m)/*先计算某月以前月份的总天数*/ {
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("data error");break;
}
sum=sum+d; /*再加上某天的天数*/
leapyes=leap(y);
if(leapyes==1&&month>2)/*如果是闰年且月份大于2,总天数应该加一天*/ sum++;
return sum;
}
void main()
{
int d1,d2,d;
printf("\n从键盘输入开始日期,格式为:年-月-日\n");
scanf("%d-%d-%d",&year,&month,&day);
d1=days(year,month,day);
printf("\n从键盘输入要判断的日期,格式为:月-日\n");
scanf("%d-%d",&month,&day);
d2=days(year,month,day);
d=d2-d1;
if(d%5==3 || d%5==4)
printf("%d\n",0);
else
printf("%d\n",1);
}
TA贡献1818条经验 获得超7个赞
#include <stdio.h>
int day,month,year,sum,leapyes;
int leap(int y)
{
if(y%400==0||(y%4==0&&y%100!=0))/*判断是不是闰年*/ return 1;
else
return 0;
}
int days( int y, int m, int d )
{
switch(m)/*先计算某月以前月份的总天数*/ {
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("data error");break;
}
sum=sum+d; /*再加上某天的天数*/
leapyes=leap(y);
if(leapyes==1&&month>2)/*如果是闰年且月份大于2,总天数应该加一天*/ sum++;
return sum;
}
void main()
{
int d1,d2,d;
printf("\n从键盘输入开始日期,格式为:年-月-日\n");
scanf("%d-%d-%d",&year,&month,&day);
d1=days(year,month,day);
printf("\n从键盘输入要判断的日期,格式为:月-日\n");
scanf("%d-%d",&month,&day);
d2=days(year,month,day);
d=d2-d1;
if(d%5==3 || d%5==4)
printf("%d\n",0);
else
printf("%d\n",1);
}
- 2 回答
- 0 关注
- 140 浏览
添加回答
举报