The total number of days required date of journey with C language switch statement

Ⅰ、用switch语句求年月日:
①、//代码摘下直接可以运行
#include<stdio.h>
int main()
{
int year,month,day,sum;
printf(“Please input the number of year,month,day\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;
}
sum=sum+day;
if(year%40&&year%100||year%4000)
SUM = +. 1;
the printf ( "% D of The SUM IS \ n-", SUM);
return 0;
}
②, the results show:
For example: This program is designed to calculate the input date is the day of the year; when the input 2019,12,27 it means: December 2019 No. 27 this year, the first few days, the result is 361 days;
Here Insert Picture Description
☺ Message:
ⅰ, this program running on the Visual C ++ version 6.0;
ⅱ, If I give the procedure in question, or there is a problem in terms of narrative, I can not read or explain the meaning, please leave a message and I pointed out or discussed, thank you big brother! ! !
Ⅲ, considering this procedure is relatively simple, but also need to consider whether or common year is a leap year, the need for "+1" operation; and switch usage once again been applied;

Published 40 original articles · won praise 0 · Views 614

Guess you like

Origin blog.csdn.net/weixin_43405300/article/details/103733210