A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 红凉梦 中级黑马   /  2016-1-23 20:32  /  543 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  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. }
复制代码

2 个回复

倒序浏览
听见你说 朝阳起又落
回复 使用道具 举报
        哦
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马