定义一个结构体变量,给定年月日确定这一天是一年中的第几天,(考虑闰年问题)
1 //定义一个结构体变量,给定年月日确定这一天是一年中的第几天,(考虑闰年问题) 2 #include<stdio.h> 3 struct 4 { 5 int year; 6 int month; 7 int day; 8 }date; 9 10 int main() 11 { 12 int days; 13 printf("input year,month,day:\n"); 14 scanf("%d,%d,%d", &date.year, &date.month, &date.day); 15 switch (date.month) 16 { 17 case 1:days = date.day; break; 18 case 2:days = date.day + 31; break; 19 case 3:days = date.day + 59; break; 20 case 4:days = date.day + 90; break; 21 case 5:days = date.day + 120; break; 22 case 6:days = date.day + 151; break; 23 case 7:days = date.day + 181; break; 24 case 8:days = date.day + 212; break; 25 case 9:days = date.day + 243; break; 26 case 10:days = date.day + 273; break; 27 case 11:days = date.day + 304; break; 28 case 12:days = date.day + 334; break; 29 } 30 if((date.year % 4 == 0 && date.year % 100 != 0 31 || date.year % 400 == 0) && date.month >=3) 32 days += 1; 33 printf("%d",days); 34 return 0; 35 }