# c语言 定义一个结构体变量（包括年、月、日）。计算该日在本年中是第几天，注意闰年问题。

1 篇文章 0 订阅
#include <stdio.h>

typedef struct
{
int year;
int month;
int day;
}time;

int panduan(int i);
int main()
{
time a;
int counter;
scanf("%d %d %d",&a.year,&a.month,&a.day);
int b=panduan(a.year);
if(b==366)
{
switch(a.month)
{
case 1:
counter=a.day;break;
case 2:
counter=a.day+31;break;
case 3:
counter=a.day+31+29;break;
case 4:
counter=a.day+31+29+31;break;
case 5:
counter=a.day+31+29+31+30;break;
case 6:
counter=a.day+31+29+31+30+31;break;
case 7:
counter=a.day+31+29+31+30+31+30;break;
case 8:
counter=a.day+31+29+31+30+31+30+31;break;
case 9:
counter=a.day+31+29+31+30+31+30+31+31;break;
case 10:
counter=a.day+31+29+31+30+31+30+31+31+30;break;
case 11:
counter=a.day+31+29+31+30+31+30+31+31+30+31;break;
case 12:
counter=a.day+31+29+31+30+31+30+31+31+30+31+30;

}
}

if(b==365)
{
switch(a.month)
{
case 1:
counter=a.day;break;
case 2:
counter=a.day+31;break;
case 3:
counter=a.day+31+28;break;
case 4:
counter=a.day+31+28+31;break;
case 5:
counter=a.day+31+28+31+30;break;
case 6:
counter=a.day+31+28+31+30+31;break;
case 7:
counter=a.day+31+28+31+30+31+30;break;
case 8:
counter=a.day+31+28+31+30+31+30+31;break;
case 9:
counter=a.day+31+28+31+30+31+30+31+31;break;
case 10:
counter=a.day+31+28+31+30+31+30+31+31+30;break;
case 11:
counter=a.day+31+28+31+30+31+30+31+31+30+31;break;
case 12:
counter=a.day+31+28+31+30+31+30+31+31+30+31+30;

}
}
//printf("%d %d %d\n",a.year,a.month,a.day);
printf("%d\n",counter);
return 0;
}
int panduan(int i)//判断是否是闰年
{
int days;
if(i%4==0||i%400==0)
days=366;

else days=365;

return days;
}

08-06 5920
05-17 3万+
05-09 7933

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

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

©️2022 CSDN 皮肤主题：书香水墨 设计师：CSDN官方博客

¥2 ¥4 ¥6 ¥10 ¥20

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