也请你要加油鸭


私信TA

用户名:ddfmcsteve

访问量:10465

签 名:

等  级
排  名 1493
经  验 2737
参赛次数 0
文章发表 26
年  龄 0
在职情况 学生
学  校 中国XX大学
专  业 材料科学与工程

  自我简介:

略略略~~~

解题思路:定义一个结构体模板,先判断是闰年还是平年,然后再分别赋值

注意事项:

参考代码:

#include<stdio.h>


struct Date {

int month;

int days;

};


int main(void)

{

struct Date leap_year[12] = {

{1, 31},{2, 29},{3, 31},{4, 30},{5, 31},{6, 30},{7, 31},{8, 31},{9, 30},{10, 31},{11, 30},{12, 31}

};                                          //闰年

struct Date non_leap_year[12] = {

{1, 31},{2, 28},{3, 31},{4, 30},{5, 31},{6, 30},{7, 31},{8, 31},{9, 30},{10, 31},{11, 30},{12, 31}

};                                         //平年

int i, x, y, z;           //x, y, z分别是年,月,日

int total = 0;        //总天数

scanf("%d %d %d", &x, &y, &z);

if ((!(x%4) && x%100) || !(x%400))        //判断是不是闰年

{

for (i = 0; i < y - 1; i++)                        //把y月之前每个月的天数加起来,然后加当月的天数

    total += leap_year[i].days;

total += z;

}

else                                                        //判断是不是平年

{

for (i = 0; i < y - 1; i++)

    total += non_leap_year[i].days;

total += z;

}

printf("%d", total);

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区