解题思路:
注意事项:
参考代码:
//结构体之时间设计
//定义一个结构体变量(包括年、月、日)。
//计算该日在本年中是第几天,注意闰年问题。
#include <stdio.h>
struct date {
int year;
int month;
int day;
} today;
struct date* getstruct(struct date*);
int fun(struct date);
int judge(int);
int main() {
getstruct(&today);
int days = fun(today);
printf("%d\n",days);
return 0;
}
struct date* getstruct(struct date* p) {
scanf("%d%d%d",&p->year,&p->month,&p->day);
return p;
}
int fun(struct date today) {
//判断闰年来区分月份
// 构建数组,再遍历到本月
//最后加上day
int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
if(judge(today.month)) arr[2] = 29;//判断闰年
int sum, i;
sum = 0;
for(i = 1;i < today.month;i++){
sum += arr[i];
} // 本月之前的月份全部加完
sum += today.day;
return sum;
}
int judge(int mth) {
int ret;
if((mth%4==0&&mth%100!=0)||mth%400==0) ret = 1;
else ret = 0;
return ret;
}
//思路:
//输入
//计算
//输出
0.0分
0 人评分
永远的丰碑 (C语言代码)浏览:652 |
数组输出 (C语言代码)浏览:767 |
简单的a+b (C语言代码)浏览:667 |
P1002 (C语言代码)浏览:970 |
不容易系列2 (C语言代码)浏览:589 |
蛇行矩阵 (C语言代码)浏览:742 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:331 |
IP判断 (C语言描述,蓝桥杯)浏览:1092 |
1025题解浏览:732 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:575 |