• <td id="ae6ms"><li id="ae6ms"></li></td>
  • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
  • <table id="ae6ms"></table>
  • <td id="ae6ms"></td>
    <td id="ae6ms"></td>
  • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
  • <td id="ae6ms"></td>
  • <table id="ae6ms"><li id="ae6ms"></li></table>
  • <table id="ae6ms"></table>
    西西軟件園多重安全檢測下載網站、值得信賴的軟件下載站!
    軟件
    軟件
    文章
    搜索

    首頁編程開發VC|VC++ → C語言實現萬年歷代碼實例

    C語言實現萬年歷代碼實例

    相關軟件相關文章發表評論 來源:本站整理時間:2010/8/29 9:32:34字體大?。?em class="fontsize">A-A+

    作者:佚名點擊:939次評論:0次標簽: C語言 萬年歷

    • 類型:源碼相關大?。?i>15.9M語言:中文 評分:3.2
    • 標簽:
    立即下載

         經過近這幾天的努力,終于寫完了這個"萬年歷"的程序了,共享一下, 特別是同"勉"共享 

    [需求]
        請打印出任意年份的日歷
    [代碼]
    #include <stdio.h>

    #define LMonth 31
    #define SMonth 30
    #define VMonth 28

    typedef
    enum {
        Sun,
        Mon,
        Jue,
        Wed,
        Thu,
        Fri,
        Sat
    } WEEK;

    typedef
    enum {
        January
    =1,
    February,
        Match,
        Apirl,
        May,
        June,
        July,
        August,
    September,
        October,
        November,
        December
    } MONTH;

    void printMonHead(void)
    {
       printf(
    "    Sun    Mon    Jue    Wed    Thu    Fri    Sat\n");
    }

    void  printMonth(const WEEK firstDay, int length )
    {
         WEEK weekDay
    = firstDay %7;

        
    int i;

         printMonHead();

        
    for (i=0; i<weekDay;++i)
         {
             printf(
    "");
         }

       
    for(i=1;i<=length;++i)
        {
              weekDay
    = (++weekDay)%7;
              printf(
    "%7d", i);

             
    if(weekDay==0) printf("\n");
        }

        printf(
    "\n");
    }


    int isLeapYear(constint yr)
    {
       
    return ( yr%( yr%100?4:400) ?0 : 1);
    }


    int getYearDay(constint year)
    {

       
    int lastYear = year-1;
       
    int yearNum = lastYear-1899;

       
    int walker,counter=0;
       
    for(walker=1900; walker < year; ++walker)
        {
           
    if(isLeapYear(walker)==1)
               
    ++counter;
        }

       
    return (365*yearNum+counter+1)%7;
    }


    void printYear(constint y)
    {
        WEEK yDay
    = getYearDay(y);
       
    int  vDay = isLeapYear(y);

       
    int monWeeks[13];
       
    int monLen  [13];

        monLen[
    0]=0;
        monLen[January]
    =31;     monLen[February]=28+vDay;   monLen[Match]=31;
        monLen[Apirl]
    =30;       monLen[May]=31;             monLen[June]=30;
        monLen[July]
    =31;        monLen[August]=31;          monLen[September]=30;
        monLen[October]
    =31;     monLen[November]=30;        monLen[December]=31;

        monWeeks[
    0]=0;
        monWeeks[January]  
    = yDay;
        monWeeks[February] 
    = ((monWeeks[January]       +monLen[January]        )%7);
        monWeeks[Match]    
    = ((monWeeks[February]      +monLen[February]       )%7);
        monWeeks[Apirl]    
    = ((monWeeks[Match]         +monLen[Match]          )%7);
        monWeeks[May]      
    = ((monWeeks[Apirl]         +monLen[Apirl]          )%7);
        monWeeks[June]     
    = ((monWeeks[May]           +monLen[May]            )%7);
        monWeeks[July]     
    = ((monWeeks[June]          +monLen[June]           )%7);
        monWeeks[August]   
    = ((monWeeks[July]          +monLen[July]           )%7);
        monWeeks[September]
    = ((monWeeks[August]        +monLen[August]         )%7);
        monWeeks[October]  
    = ((monWeeks[September]     +monLen[September]      )%7);
        monWeeks[November] 
    = ((monWeeks[October]       +monLen[October]        )%7);
        monWeeks[December] 
    = ((monWeeks[November]      +monLen[November]       )%7);

       
    int i;
       
    for(i=January; i<=December; ++i)
        {
            printf(
    "\n-------------------------------------------------\n");
            printf(
    "                     %d, %d                      \n",y,i);
            printf(
    "-------------------------------------------------\n");
            printMonth(monWeeks[i],monLen[i]);
            printf(
    "\n");
        }

       
    return;
    }


    int main(void)
    {
    //  int y3 = 2000;
    //  int y3 = 1946;
    //  printYear(y3);
    int y;
     
    int quit=0;

     
    do
        {
            printf(
    "Please enter which Year to Print For You (0 to quit): ");
            scanf(
    "%d",&y);
            printf(
    "\n");

           
    if(y==0)
                quit
    =1;
           
    else
                printYear(y);

        }
    while(!quit);

     
    return0;
    }
     
     
    [輸出]
    Please enter which Year to Print For You (0 to quit): 1973
     
     
    Please enter which Year to Print For You (0 to quit): 1973
     
     

     
     
     
    -------------------------------------------------
                         1946, 1                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                        1      2      3      4      5
          6      7      8      9     10     11     12
         13     14     15     16     17     18     19
         20     21     22     23     24     25     26
         27     28     29     30     31
     
     
    -------------------------------------------------
                         1946, 2                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                                             1      2
          3      4      5      6      7      8      9
         10     11     12     13     14     15     16
         17     18     19     20     21     22     23
         24     25     26     27     28
     
     
    -------------------------------------------------
                         1946, 3                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                                             1      2
          3      4      5      6      7      8      9
         10     11     12     13     14     15     16
         17     18     19     20     21     22     23
         24     25     26     27     28     29     30
         31
     
     
    -------------------------------------------------
                         1946, 4                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri   Sat
                 1      2      3      4      5      6
          7      8      9     10     11     12     13
         14     15     16     17     18     19     20
         21     22     23     24     25     26     27
         28     29     30
     
     
    -------------------------------------------------
                         1946, 5                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                               1      2      3      4
          5      6      7      8      9     10     11
         12     13     14     15     16     17     18
         19     20     21     22     23     24     25
         26     27     28     29     30     31
     
     
    -------------------------------------------------
                         1946, 6                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                                                    1
          2      3      4      5      6      7      8
          9     10     11     12     13     14     15
         16     17     18     19     20     21     22
         23     24     25     26     27     28     29
         30
     
     
    -------------------------------------------------
                         1946, 7                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                 1      2      3      4      5      6
          7      8      9     10     11     12     13
         14     15     16     17     18     19     20
         21     22     23     24     25     26     27
         28     29     30     31
     
     
    -------------------------------------------------
                         1946, 8                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed   Thu    Fri    Sat
                                      1      2      3
          4      5      6      7      8      9     10
         11     12     13     14     15     16     17
         18     19     20     21     22     23     24
         25     26     27     28     29     30     31
     
     
     
    -------------------------------------------------
                         1946, 9                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
          1      2      3      4      5      6      7
          8      9     10     11     12     13     14
         15     16     17     18     19     20     21
         22     23     24     25     26     27     28
         29     30
     
     
    -------------------------------------------------
                         1946, 10                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                        1      2      3      4      5
          6      7      8      9     10     11     12
         13     14     15     16     17     18     19
         20     21     22     23     24     25     26
         27     28     29     30     31
     
     
    -------------------------------------------------
                         1946, 11                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
                                             1      2
          3      4      5      6      7      8      9
         10     11     12     13     14     15     16
         17     18     19     20     21     22     23
         24     25     26     27     28     29     30
     
     
     
    -------------------------------------------------
                         1946, 12                     
    -------------------------------------------------
        Sun    Mon    Jue    Wed    Thu    Fri    Sat
          1      2      3      4      5      6      7
          8      9     10     11     12     13     14
         15     16     17     18     19     20     21
         22     23     24     25     26     27     28
         29     30     31
     

      相關評論

      閱讀本文后您有什么感想? 已有人給出評價!

      • 8 喜歡喜歡
      • 3 頂
      • 1 難過難過
      • 5 囧
      • 3 圍觀圍觀
      • 2 無聊無聊

      熱門評論

      最新評論

      第 1 樓 四川鐵通 網友 客人 發表于: 2011/6/8 22:29:30
      代碼不對,有個 yr找不到

      支持( 0 ) 蓋樓(回復)

      發表評論 查看所有評論(0)

      昵稱:
      表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
      字數: 0/500 (您的評論需要經過審核才能顯示)
      女人让男人桶30分钟免费视频,女人张开腿让男人桶个爽,一进一出又大又粗爽视频
    • <td id="ae6ms"><li id="ae6ms"></li></td>
    • <xmp id="ae6ms"><td id="ae6ms"></td><table id="ae6ms"></table>
    • <table id="ae6ms"></table>
    • <td id="ae6ms"></td>
      <td id="ae6ms"></td>
    • <table id="ae6ms"></table><table id="ae6ms"><td id="ae6ms"></td></table>
    • <td id="ae6ms"></td>
    • <table id="ae6ms"><li id="ae6ms"></li></table>
    • <table id="ae6ms"></table>