/*
输入某年某月某日,判断这一天是这一年的第几天?
*/
#include<stdio.h> int Leap(int); int main(void) { int year = 0, month = 0, day = 0, temp = 0; printf("输入某年某月某日,输入样例如:2015,5,5\n"); scanf("%d,%d,%d", &year, &month, &day); //判断平年还是闰年 switch(month) { case 1: temp = 0; break; case 2: temp = 31; break; case 3: temp = 59; break; case 4: temp = 90; break; case 5: temp = 120; break; case 6: temp = 151; break; case 7: temp = 181; break; case 8: temp = 212; break; case 9: temp = 243; break; case 10: temp = 273; break; case 11: temp = 304; break; case 12: temp = 334; break; } if (Leap(year) == 1 && month > 2) { temp = temp + day + 1; } else { temp = temp + day; } printf("%d\n", temp); return 0; } int Leap(int x) //判断是否为闰年 { if ((x%100!=0 && x%4==0) || (x%100==0 && x%400==0)) { return 1; } else { return 0; } }
时间: 2024-10-12 22:05:17