qq_皮皮博_cemsEH
2021-08-15 22:48
#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;
}
需要呀,月份数用for更简单
C语言入门
926206 学习 · 20797 问题
相似问题