美文网首页
万年历(1990之后)

万年历(1990之后)

作者: 萌面大叔2 | 来源:发表于2017-02-15 13:07 被阅读0次

    1. 万年历(1990之后)

    #include<stdio.h>
    int main()
    {
        int year,month;
        int i=1900;
        int sum=0;
        int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        printf("please input year and month:"); 
        scanf("%d%d",&year,&month);
        if(year<1990 || (month<1 || month>12))
        {
            printf("input error");
        }   
        else
        {
    
            while(i<year)
            {
                if((i%4==0 && i%100!=0) || i%400==0)
                {
                     sum+=366;
                }    
                else
                {
                     sum+=365;
                }
                i++;
            }
            if((year%4==0 && year%100!=0) || year%400==0)
            {
                a[2]=29;
            }
            else
            {
                a[2]=28;
    
            }
            printf("%d\n",a[2]);
            int j=1;
            while(j<month)
            {
                sum=sum+a[j];
                j++;
            }
    
        }
        
        int week=sum%7;
        //printf("week=%d\n",week);
        week=(week+1)%7;
        printf("\t\t\t%d/%d\n",year,month);
        printf("Sun\tMon\tTues\tWed\tThur\tFri\tSat\n");
        int colum=0;
         i=1;
         int b=a[month];
        while (i<=week)
        {
            printf("\t");
            i++;
            colum++;
        }
         i=1;
        while(i<=b)
        {
            printf("%2d\t",i);
            colum++;
            if(colum%7==0)
            {
                printf("\n");
            }
            i++;
        }
        printf("\n");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:万年历(1990之后)

          本文链接:https://www.haomeiwen.com/subject/hohnyttx.html