302班

          java突擊隊
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          日期(today tomorrow)利用struct

          Posted on 2007-07-02 16:19 停留的風 閱讀(352) 評論(0)  編輯  收藏 所屬分類: C語言學習歷程

          #include <stdio.h>

          struct date
           {
             int month;
             int day;
             int year;
           };
          int main(void)
          {
              struct date today,tomorrow; 
              int numberOfDays(struct date d);

           printf("Enter today's date(mm dd yyyy):\n");
           scanf("%i %i %i",&today.month,&today.day,&today.year);
             
           if(today.day!=numberOfDays(today))
           {
             tomorrow.day=today.day+1;
             tomorrow.month=today.month;
             tomorrow.year=today.year;
              }
           else if(today.month!=12)
           {
             tomorrow.day=1;
             tomorrow.month=today.month+1;
             tomorrow.year=today.year;
           }
           else
           {
             tomorrow.day=1;
             tomorrow.month=1;
             tomorrow.year=today.year+1;
           }

           printf("Tomorrow's date is %i  %i  %.2i.\n",tomorrow.month,tomorrow.day,tomorrow.year%100);
           return 0;
           
          }

          int numberOfDays(struct date d)
          {
            int days;
            bool isLeapYear(struct date d);
            const int daysPerMonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
           
            if(isLeapYear(d)==1&&d.month==2)
            {
              days=29;
            }
            else
             days=daysPerMonth[d.month-1];
            return days;
          }

          bool isLeapYear(struct date d)
          {
            bool leapYearFlag;
            if((d.year%4==0&&d.year%100!=0)||d.year%400==0)
            {
              leapYearFlag=1;
            }
            else
           leapYearFlag=0;
            return leapYearFlag;
          }
          運行結果:

          主站蜘蛛池模板: 滕州市| 阳新县| 英德市| 德化县| 闽清县| 洛宁县| 南木林县| 肇庆市| 托克逊县| 浮梁县| 平顶山市| 洛宁县| 福州市| 芦溪县| 响水县| 盐山县| 阜康市| 手游| 大埔县| 长宁县| 奉化市| 永年县| 兴义市| 武宁县| 藁城市| 祥云县| 昆山市| 玉树县| 惠州市| 车险| 方正县| 章丘市| 富源县| 乌拉特前旗| 中阳县| 新巴尔虎左旗| 禹城市| 县级市| 河北省| 宝清县| 浠水县|