我也做过一个这样类似的题,不过我自己写的太啰嗦,贴给你看一下,希望可以帮到你,剩余天数减一下就好了。
/*
题目:输入某年某月某日,判断这一天是这一年的第几天?
*/
#include<stdio.h>
void main()
{
int year,month,day;
int i = 0;
int sum_1,sum_2,sum_3,sum_4,sum_5,sum_6,sum_7,sum_8,sum_9,sum_10,sum_11;
sum_1 = 31;sum_2=sum_1+28;sum_3=sum_2+31;sum_4=sum_3+30;sum_5=sum_4+31;
sum_6=sum_5+30;sum_7=sum_6+31;sum_8=sum_7+31;sum_9=sum_8+30;
sum_10=sum_9+31;sum_11=sum_10+30;
printf("年:");
scanf("%d",&year);
printf("月:");
scanf("%d",&month);
printf("日:");
scanf("%d",&day);
if(year%4 == 0)
{
switch(month)
{
case 1:
i=day;
break;
case 2:
i=sum_1 + day;
break;
case 3:
i=sum_2 + day + 1;
break;
case 4:
i=sum_3 + day + 1;
break;
case 5:
i=sum_4 + day + 1;
break;
case 6:
i=sum_5 + day + 1;
break;
case 7:
i=sum_6 + day + 1;
break;
case 8:
i=sum_7 + day + 1;
break;
case 9:
i=sum_8 + day + 1;
case 10:
i=sum_9 + day + 1;
break;
case 11:
i=sum_10 + day + 1;
break;
case 12:
i=sum_11 + day + 1;
break;
}
}
else
{
switch(month)
{
case 1:
i=day;
break;
case 2:
i=sum_1 + day;
break;
case 3:
i=sum_2 + day;
break;
case 4:
i=sum_3 + day;
break;
case 5:
i=sum_4 + day;
break;
case 6:
i=sum_5 + day;
break;
case 7:
i=sum_6 + day;
break;
case 8:
i=sum_7 + day;
case 9:
i=sum_8 + day;
break;
case 10:
i=sum_9 + day;
break;
case 11:
i=sum_10 + day;
break;
case 12:
i=sum_11 + day;
break;
}
}
printf("这一天是这一年的第%d天\n",i);
}
/*
题目:输入某年某月某日,判断这一天是这一年的第几天?
*/
#include<stdio.h>
void main()
{
int year,month,day;
int i = 0;
int sum_1,sum_2,sum_3,sum_4,sum_5,sum_6,sum_7,sum_8,sum_9,sum_10,sum_11;
sum_1 = 31;sum_2=sum_1+28;sum_3=sum_2+31;sum_4=sum_3+30;sum_5=sum_4+31;
sum_6=sum_5+30;sum_7=sum_6+31;sum_8=sum_7+31;sum_9=sum_8+30;
sum_10=sum_9+31;sum_11=sum_10+30;
printf("年:");
scanf("%d",&year);
printf("月:");
scanf("%d",&month);
printf("日:");
scanf("%d",&day);
if(year%4 == 0)
{
switch(month)
{
case 1:
i=day;
break;
case 2:
i=sum_1 + day;
break;
case 3:
i=sum_2 + day + 1;
break;
case 4:
i=sum_3 + day + 1;
break;
case 5:
i=sum_4 + day + 1;
break;
case 6:
i=sum_5 + day + 1;
break;
case 7:
i=sum_6 + day + 1;
break;
case 8:
i=sum_7 + day + 1;
break;
case 9:
i=sum_8 + day + 1;
case 10:
i=sum_9 + day + 1;
break;
case 11:
i=sum_10 + day + 1;
break;
case 12:
i=sum_11 + day + 1;
break;
}
}
else
{
switch(month)
{
case 1:
i=day;
break;
case 2:
i=sum_1 + day;
break;
case 3:
i=sum_2 + day;
break;
case 4:
i=sum_3 + day;
break;
case 5:
i=sum_4 + day;
break;
case 6:
i=sum_5 + day;
break;
case 7:
i=sum_6 + day;
break;
case 8:
i=sum_7 + day;
case 9:
i=sum_8 + day;
break;
case 10:
i=sum_9 + day;
break;
case 11:
i=sum_10 + day;
break;
case 12:
i=sum_11 + day;
break;
}
}
printf("这一天是这一年的第%d天\n",i);
}