黑马程序员技术交流社区

标题: 结构体的一下小代码 [打印本页]

作者: 红凉梦    时间: 2016-1-23 20:32
标题: 结构体的一下小代码
  1. #include<stdio.h>
  2. //1
  3. struct Date
  4. {
  5.     int year;
  6.     int month;
  7.     int day;
  8. };
  9. //2
  10. int isRunNian(int nian);
  11. int isRunNian(int nian)
  12. {
  13.     return (nian%4==0&&nian%100!=0)||(nian%400==0)?1:0;
  14. }
  15. //3
  16. void totalDaysOfThisYear(struct Date wuse)
  17. {
  18.     int totalDaysOfThisYear = 0;
  19.     switch (wuse.month) {// 12 月 25日
  20.         case 12:
  21.             totalDaysOfThisYear =totalDaysOfThisYear + 30;
  22.         case 11:
  23.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  24.         case 10:
  25.             totalDaysOfThisYear =totalDaysOfThisYear + 30;
  26.         case 9:
  27.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  28.         case 8:
  29.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  30.         case 7:
  31.             totalDaysOfThisYear =totalDaysOfThisYear + 30;
  32.         case 6:
  33.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  34.         case 5:
  35.             totalDaysOfThisYear =totalDaysOfThisYear + 30;
  36.         case 4:
  37.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  38.         case 3:
  39.             totalDaysOfThisYear =totalDaysOfThisYear + isRunNian(wuse.year)?29:28;
  40.         case 2:
  41.             totalDaysOfThisYear =totalDaysOfThisYear + 31;
  42.         case 1:
  43.         default:
  44.             break;
  45.     }
  46.    
  47.    totalDaysOfThisYear = totalDaysOfThisYear + wuse.day;
  48.     printf("----=------%d\n",totalDaysOfThisYear);
  49. }


  50. int main()
  51. {
  52. //    int result = isRunNian(2008);
  53. //    result?printf("闰年\n"):printf("平年");
  54.     struct Date date = {2015,3,1};
  55.     totalDaysOfThisYear(date);
  56.     return 0;
  57. }
复制代码

作者: 水丹青    时间: 2016-1-23 21:10
听见你说 朝阳起又落
作者: suihaixia54    时间: 2016-1-24 10:36
        哦




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2