某月某日是某年的第几天

来源:互联网 发布:vb.net 多线程实例 编辑:程序博客网 时间:2024/05/09 02:46

题目描述

定义一个结构体变量(包括年、月、日)。计算该日在本年中是第几天,注意闰年问题。

输入

年月日

输出

当年第几天

样例输入

2000 12 31

样例输出

366


#include <stdio.h>int dayOfMonth[13] = {0,31,60,91,121,152,182,213,244,274,305,335,366};int main() {int m,year,month,date;while (scanf("%d %d %d\n",&year,&month,&date)!=EOF) {if(year%4 == 0 && year%100 !=0 || year%400 == 0) {               if(month<=2)  printf("%d\n",(month-1)*31+date);if (month>2) {           int total= dayOfMonth[month-1]+date;printf("%d\n",total );}} else {if(month<=2)  printf("%d\n",(month-1)*31+date);if (month>2) {       int total= dayOfMonth[month-1]+date-1;printf("%d\n",total );}}}return 0;}




原创粉丝点击