高分求C持续的编写(简单题)
题目:输入某年某月某日,判断这一天是这一年的第几天?
要求:程序完整的编写
程序流程
谢谢了,大虾们帮写一下,200高分求解,正确的话可以加分!
参考答案:分就不一定要啦,没有检查输入的日期是否是合法的,算是不完美的
#include <stdio.h>
int runnian(int year) //检查是否是闰年
{
if(year % 100 == 0)
{
if (year%400 == 0)
{
return 1;
}
else
{
return 0;
}
}
else
{
if(year % 4 == 0)
{
return 1;
}
else
{
return 0;
}
}
}
void main(int argc, char *argv[])
{
int year,month,day;
int sum = 0;
printf("Please input year,month,day\n");
scanf("%d%d%d",&year,&month,&day);
if (runnian(year))
sum = 366;
else
sum = 365;
switch (month)
{
case 1:
sum -= 31; //不要break;
case 2:
sum -= (runnian(year)?29:28);
case 3:
sum -= 31;
case 4:
sum -= 30;
case 5:
sum -= 31;
case 6:
sum -= 30;
case 7:
sum -= 31;
case 8:
sum -= 31;
case 9:
sum -= 30;
case 10:
sum -= 31;
case 11:
sum -= 30;
case 12:
sum -= 31;
}
sum += day;
printf("%d\n",sum);
}