#include <stdio.h>
void main()
{
int month, d, day, year, leap;
printf("please a date: \n");
scanf("%d %d %d",&year, &month, &d);
if ( year % 4 == 0 )
{
if ( year % 100 == 0 )
{
if ( year % 400 == 0 )
{
leap = 1;
}
else leap = 1;
}
}
else leap = 0;
if ( leap )
{
if ( month > 3 )
{
day = 31;
printf("This is %d year %d days\n", year,(month-1)*31+d);pause;
}
else if ( month = 2 )
{
day = 28;
printf("This is %d year %d days\n", year,31+d);pause;
}
}else
switch (month)
{
case 1: printf("This is %d year %d days\n", year,d); break;
case 2: printf("This is %d year %d days\n", year,31+d); break;
case 3: printf("This is %d year %d days\n", year,61+d); break;
case 4: printf("This is %d year %d days\n", year,2*31+30+d); break;
case 5: printf("This is %d year %d days\n", year,2*(30+31)+d); break;
case 6: printf("This is %d year %d days\n", year,3*31+2*30+d); break;
case 7: printf("This is %d year %d days\n", year,3*(30+31)+d); break;
case 8: printf("This is %d year %d days\n", year,4*31+3*30+d); break;
case 9: printf("This is %d year %d days\n", year,5*31+3*30+d); break;
case 10: printf("This is %d year %d days\n", year,5*31+4*30+d); break;
case 11: printf("This is %d year %d days\n", year,6*31+4*30+d); break;
case 12: printf("This is %d year %d days\n", year,6*31+5*30+d); break;
default: printf("input error!!!!!\n");
}
}
这是我写的代码,我觉得代码量太多了,关于这个问题能有好的办法么??请大神帮忙。。。这是小甲鱼视频里的题目。。 |