题目:
输入某年某月某日,判断这一天是这一年的第几天?
代码:
#include <stdio.h>
#include <stdlib.h>
void test ()
{
int num;
int year,month,day;
printf("请输入年月日,请用空格隔开,示例格式2020 2 2\n");
scanf("%d %d %d",&year,&month,&day);
switch(month)
{
case 1:
num=0;break;
case 2:
num=1*31;break;
case 3:
num=1*31+28;break;
case 4:
num=2*31+28;break;
case 5:
num=2*31+28+1*30;break;
case 6:
num=3*31+28+1*30;break;
case 7:
num=3*31+28+2*30;break;
case 8:
num=4*31+28+2*30;break;
case 9:
num=5*31+28+2*30;break;
case 10:
num=5*31+28+3*30;break;
case 11:
num=6*31+28+3*30;break;
case 12:
num=6*31+28+4*30;break;
}
if(year%4==0&&year%100!=0&&year%400==0&&month>2)
{
num+=1;
}
num+=(day);
printf("这是这一年的第%d天",num);
}
int main()
{
test();
system("pause");
return 0;
}