C语言练习代码-5

题目:输入某年某月某日,判断这一天是这一年的第几天? 

C语言练习代码-5
 1 #include <stdio.h>
 2 
 3 int main(void)
 4 {
 5     int year , month ,day ,sum;
 6     scanf("%d-%d-%d",&year,&month,&day);
 7     switch(month){
 8              case 1: sum=0;break;
 9              case 2: sum=31; break;
10              case 3: sum=31+28; break;
11              case 4: sum=31+28+31; break;
12              case 5: sum=31+28+31+30; break;         
13              case 6: sum=31+28+31+30+31; break; 
14              case 7: sum=31+28+31+30+31+30; break;  
15              case 8: sum=31+28+31+30+31+30+31; break;  
16              case 9: sum=31+28+31+30+31+30+31+31; break;
17              case 10: sum=31+28+31+30+31+30+31+31+30; break;   
18              case 11: sum=31+28+31+30+31+30+31+31+30+31; break; 
19              case 12: sum=31+28+31+30+31+30+31+31+30+31+30; break;  
20              default: printf("invalid input") ;return 0 ;                
21                   }
22         sum=sum+day;
23         
24         if(year/400==0||year/4==0&&year/100!=0)//判断闰年 
25         {
26            sum++;
27         }
28         printf("%d",sum);
29         
30         scanf("%d",&sum);
31     return 0;
32 }
C语言练习代码-5

C语言练习代码-5

上一篇:帮哥们做的一个整理文档的小工具(C++ string的标准函数还是很给力的,代码在最下)


下一篇:C语言练习代码-7