使用switch语句编写“显示某年某月的天数”程序:

2024年11月15日 00:22
有4个网友回答
网友(1):

瑞年的判断标准是:能够被400整除或者能被4整除而不能被100整除,这些年为瑞年。switch (m){case 1,3,5,7,8,10,12: day=31; break;case 4,6,9,11: day=30; break;case 2: if(y%400==0 || (y%4==0 && y%100>0)) day=29; else day=28;}其他自己补充。

网友(2):

#include
#include

void main(void)
{
int year;
int month;
int day;
int sum;
int leap;

printf("请输入年月日,用,隔开\n");
scanf("%d,%d,%d", &year, &month, &day);

switch (month)
{
case 1:
sum = 0;
break;
case 2:
sum = 31;
break;
case 3:
sum = 59;
break;
case 4:
sum = 90;
break;
case 5:
sum = 120;
break;
case 6:
sum = 151;
break;
case 7:
sum = 181;
break;
case 8:
sum = 212;
break;
case 9:
sum = 243;
break;
case 10:
sum = 273;
break;
case 11:
sum = 304;
break;
case 12:
sum = 334;
break;
default:
printf("您输入的月份有误\n");
break;
}

sum += day;

if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
{
leap = 1;
}
else
{
leap = 0;
}

if (leap == 1 && month > 2)
{
sum++;
}

printf("%d年%d月%d日是当年的第%d天\n", year, month, day, sum);

system("pause");
return;

}

网友(3):

#includevoid main(){ int iYears,iMonths,iItem,iItem1,iFun,iDays; iFun=1; printf(" Please enter year and month:"); scanf("%d,%d",&iYears,&iMonths); if(iMonths<1||iMonth>12) {printf("输入的月份有误,程序退出");return;

} iItem=iYears%4; iItem1=iYears%100; if(iItem!=0) iFun=0; if(iItem==0&&iItem1!=0) iFun=0;switch(iMonths) {case 2 : if(iFun==0) iDays=28;else iDays=29;break;

case 4 : iDays=30;break;

case 6 : iDays=30;break;

case 9 : iDays=30;break;

case 11: iDays=30;break;

default: iDays=31;

} printf("%d %d is %d days",iYears,iMonths,iDays); }

网友(4):

用什么语言实现啊?