c语言该年的第几天,C语言,一年中的第几天

C语言,一年中的第几天0

#includestruct Date

{

int year;

int month;

int day;

};

typedef struct Date Date;int checkinput(Date date);//检查输入是否有错

int days(Date date);//统计天数

int leap(Date date);//判断是不是闰年int main()

{

Date date;

int totalday; printf("请输入日期,年 月 日\n");

scanf("%d %d %d",&date.year,&date.month,&date.day); if(checkinput(date))

{

totalday=days(date);

printf("%d年%d月%d日是该年的第%d天\n",date.year,date.month,date.day,totalday);

}

else

{

printf("请退出\n");

} return 0;

}int checkinput(Date date)

{

int flag=1;

int leap1;

leap1=leap(date);

if(date.month>12)

{

printf("不存在的月份\n");

flag=0;

}

if((date.month==1||date.month==3||date.month==5||date.month==7||date.month==8||date.month==10||date.month==12)&&date.day>31)

{

printf("天数过大\n");

flag=0;

}

if((date.month==4||date.month==6||date.month==9||date.month==11)&&date.day>30)

{

printf("天数过大\n");

flag=0;

}

if(leap1==1&&date.month==2&&date.day>29)

{

printf("天数过大\n");

flag=0;

}

if (leap1==0&&date.month==2&&date.day>28)

{

printf("天数过大\n");

flag=0;

}

return flag;

}int leap(Date date)

{

int leap=0;

if((date.year%4==0&&date.year%100!=0)||date.year%400==0)

leap=1;

return leap;

}int days(Date date)

{

int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int total=0;

int i; if(leap(date)==1)

monthdays[1]=29;

for(i=date.month-2;i>=0;i++)

total+=monthdays[i];

total+=date.day;

return total;

}2月及其以后的月份出错!!!!求救

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值