需要用到for循环不
#include <stdio.h>
int main()
{
/* 定义需要计算的日期 */
int year = 2008;
int month = 8;
int day = 8;
if (year % 4 == 0 && year % 100 != 0 && month>0)
{
for(month=8;month>0;month--)
switch (month)
{
case 7:day += 31; printf("%d\n", day); break;
case 6:day += 30; printf("%d\n", day); break;
case 5:day += 31; printf("%d\n", day); break;
case 4:day += 30; printf("%d\n", day); break;
case 3:day += 31; printf("%d\n", day); break;
case 2:day += 29; printf("%d\n", day); break;
case 1:day += 31; printf("%d\n", day); break;
}
}
else
{
for (month = 8; month > 0; month--)
switch (month)
{
case 7:day += 31; printf("%d\n", day); break;
case 6:day += 30; printf("%d\n", day); break;
case 5:day += 31; printf("%d\n", day); break;
case 4:day += 30; printf("%d\n", day); break;
case 3:day += 31; printf("%d\n", day); break;
case 2:day += 28; printf("%d\n", day); break;
case 1:day += 31; printf("%d\n", day); break;
}
}
printf("2008年8月8日是该年的第%d天", day);
return 0;
}