- # include <stdio.h>
- int main()
- {
- int leap(int); //判断是否是闰年的函数声明;
- int number(int, int, int); //求天数的函数声明;
- int year, month, day;
- while (scanf("%d%d%d", &year, &month, &day) != EOF) //输入年月日 如 2004 3 1
- {
- printf("%d年%d月%d日是今年的第%d天!\n", year, month, day, number(year, month, day)); //输出
- }
- return 0;
- }
- int leap(int year) //判断平年闰年的函数
- {
- if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) return 1; //判断闰年
- else return 0;
- }
- int number(int year, int month, int day) //求天数的函数
- {
- int sum = 0;
- int month_p[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- int month_r[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (leap(year)) //是闰年返回1, 不是闰年返回0 0为假 非0为真
- {
- for (int i = 0; i < month - 1; i++)
- {
- sum += month_r[i];
- }
- }
- else
- {
- for (int i = 0; i < month - 1; i++)
- {
- sum += month_p[i];
- }
- }
- sum += day;
- return (sum);
- }
复制代码 |
|