马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
/*
题目:输入某年某月某日,判断这一天是这一年的第几天?
特殊情况,闰年且输入月份大于3时需考虑多加一天
*/
typedef enum {
Jan = 31,Feb = 28,Mar = 31,Apr = 30,May = 31,June = 30,
July = 31,Aug = 31,Sep = 30,Oct = 31,Nov = 30,Dec = 31
}month_day;
int _4_main()
{
int count_day = 0;
int year,month,day;
printf("输入年月日(yyyy-mm-dd):");
scanf("%d-%d-%d",&year,&month,&day);
count_day += day;
// 判断是否是闰年
_Bool flag = 0;
if(((year%100!= 0)&&(year%4 == 0))||(year%100 != 0)&&(year%400 == 0)) flag == 1;
switch (month) {
case 12:count_day += Nov;
case 11:count_day += Oct;
case 10:count_day += Sep;
case 9:count_day += Aug;
case 8:count_day += July;
case 7:count_day += June;
case 6:count_day += May;
case 5:count_day += Apr;
case 4:count_day += Mar;
case 3:count_day += (flag ? Feb+1 : Feb);
case 2:count_day += Jan;
case 1:;
}
printf("%d-%02d-%02d是一年中的第%d天",year,month,day,count_day);
return 0;
}
|