用c语言编写万年历系统,编程求大神支招

2024-11-02 15:31:27
推荐回答(1个)
回答1:

#include
main()
{
   for(;;)
      {
        int nian,yue,a,b,m,c,_m=28;
        long e;
        printf("请输入年份:");
        scanf("%d",&nian);
        e=nian;
        e=e-1;
        e=(e*365+e/4)%7;
        m=e;
        if((nian%4==0)||(nian%100==0)&&(nian%400!=0))
        _m++;
        printf("%d年的日历:",nian);
         
        for(yue=1;yue<=12;yue++)
          {
            if  (yue==1||yue==3||yue==5||yue==7||yue==8||yue==10||yue==12)
                {
                   c=0;
                   printf("\n");
                   printf("            %d月     \n",yue);
                   printf(" 日  一  二  三  四  五  六\n");
                      
                   for(b=1;b<=m;b++) 
                     {
                        c++;
                        printf("    ");
                      }
                  
                   for(a=1;a<=31;a++)
                     {
                        c++;
                        if(c%7-1==0&&c!=1) printf("\n");
                        if(a<10) printf(" ");
                           printf(" %d ",a);
                        m++;
                        if(m==7) 
                        m=0;
                      }
                    printf("\n");
                  }
            else
                 {
                    if(yue==4||yue==6||yue==9||yue==11||yue==2)
                      {
                        if  (yue==2)
   {
                                     c=0;
                                     printf("\n");
                                     printf("            %d月     \n",yue);
                                     printf(" 日  一  二  三  四  五  六\n");
                               
                                     for(b=1;b<=m;b++)
                                       {
                                           c++;
                                           printf("    ");
                                        }
                                     for(a=1;a<=_m;a++)
                                       {
                                          c++;
                                          if(c%7-1==0&&c!=1)
                                             printf("\n");
                                          if(a<10)
                                             printf(" ");
                                          printf(" %d ",a);
                                          m++;
                                          if(m==7)
                                          m=0;
                                        }
       念搜返                               printf("\n");
                                   }
                           else 
{
                                      c=0;
                                      printf("\n");
        漏凯                              printf("            %d月     \n",yue);
                                      printf(" 日  一  二  三  四  五  六\n");
                          
                                      for(b=1;b<=m;b++)
                                        {
                                            c++;
                                            printf("    ");
                                         }
                                      for(a=1;a<=30;a++)
                                        {
                                            c++;
                                           if(c%7-1==0&&c!=1)
                                               printf("\n");
                                           if(a<10)
                                               printf(" ");
                       仔饥                    printf(" %d ",a);
                                           m++;
                                           if(m==7)
                                           m=0;
                                         }
                                      printf("\n");
                                   }
                          }
                  }
          }
      }
}