/* 题目:
* 输入某年某月某日,判断这一天是这一年的第几天?
*/
/* 分析:
* 以3月5日为例,应该先把前两个月的加起来,然后
* 再加上5天即为本年的第几天,特殊情况,闰年且
* 月份大于3时需考虑多加一天。
*/
#include <stdio.h>
void main()
{
int year, month, day, num=0;
printf("请输入年/月/日:\n");
printf("年:");
scanf("%d", &year);
printf("月:");
scanf("%d", &month);
printf("日:");
scanf("%d", &day);
if( day<1 && day>31)
printf("请输入正确的日期!");
switch( month-1 )
{
case 12:
num+=31;
case 11:
num+=30;
case 10:
num+=31;
case 9:
num+=30;
case 8:
num+=31;
case 7:
num+=31;
case 6:
num+=30;
case 5:
num+=31;
case 4:
num+=30;
case 3:
num+=31;
case 2:
num+=28;
case 1:
num+=31;
break;
case 0:
break;
default:printf("请输入正确的月份!");
}
if( year%400 == 0 )
{
num+=1;
}
else if( year%100 == 0 )
{
num+=0;
}
else if( year%4 == 0 )
{
num+=1;
}
else
{
num+=0;
}
num = num + day;
printf("这一天是这一年的第%d天!\n",num);
}
* 输入某年某月某日,判断这一天是这一年的第几天?
*/
/* 分析:
* 以3月5日为例,应该先把前两个月的加起来,然后
* 再加上5天即为本年的第几天,特殊情况,闰年且
* 月份大于3时需考虑多加一天。
*/
#include <stdio.h>
void main()
{
int year, month, day, num=0;
printf("请输入年/月/日:\n");
printf("年:");
scanf("%d", &year);
printf("月:");
scanf("%d", &month);
printf("日:");
scanf("%d", &day);
if( day<1 && day>31)
printf("请输入正确的日期!");
switch( month-1 )
{
case 12:
num+=31;
case 11:
num+=30;
case 10:
num+=31;
case 9:
num+=30;
case 8:
num+=31;
case 7:
num+=31;
case 6:
num+=30;
case 5:
num+=31;
case 4:
num+=30;
case 3:
num+=31;
case 2:
num+=28;
case 1:
num+=31;
break;
case 0:
break;
default:printf("请输入正确的月份!");
}
if( year%400 == 0 )
{
num+=1;
}
else if( year%100 == 0 )
{
num+=0;
}
else if( year%4 == 0 )
{
num+=1;
}
else
{
num+=0;
}
num = num + day;
printf("这一天是这一年的第%d天!\n",num);
}