周周Jay2025
2019-08-13 21:18
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int j=0;
int i;
for(i=1;i<month;i++)
{
switch(i)
{
case 1:
j += 31;
break;
case 2:
if(year%400==0||year%4==0&&year%100!=0)
{
j+= 29;
}
else
{
j += 28;
}
break;
case 3:
j += 31;
break;
case 4:
j += 30;
break;
case 5:
j += 31;
break;
case 6:
j += 30;
break;
case 7:
j+= 31;
break;
case 8:
j+= 31;
break;
case 9:
j += 30;
break;
case 10:
j += 31;
break;
case 11:
j += 30;
break;
case 12:
j += 31;
break;
}
}
j += day;
printf("%d年%d月%d日是该年的第%d天",year,month,day,j);
return 0;
}
switch(month)的话,case的结构就要变。
第一个问题呢?
#include <stdio.h>
int main()
{
int year = 2008;
int month = 8;
int day = 8;
int today=0,r=0;
if((year%4==0&&year%100!=0)||year%400==0)
r=1;
switch(month-1)
{
case 11:today+=30;
case 10:today+=31;
case 9:today+=30;
case 8:today+=31;
case 7:today+=31;
case 6:today+=30;
case 5:today+=31;
case 4:today+=30;
case 3:today+=31;
case 2:today+=28+r;
case 1:today+=31;
case 0:today+=day;
break;
}
printf("%d年%d月%d日是该年的第%d天",year,month,day,today);
return 0;
}
C语言入门
926020 学习 · 20793 问题
相似问题