解题思路:定义一个结构体模板,先判断是闰年还是平年,然后再分别赋值
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:710 |
点我有惊喜!你懂得!浏览:3887 |
C语言训练-求PI* (C语言代码)浏览:897 |
简单的a+b (C语言代码)浏览:723 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:1885 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:277 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:691 |
1024题解浏览:811 |
1128题解(返回值为数组的情况)浏览:474 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:324 |