当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

一个日期推算的程序

        #include<stdio.h>
    #define judge(y)  (y%4==0)&&(y%100!=0)(y%400==0)
    int allday(int x);
     int month1[]=;
     int month2[]=;

    void main()
    { int i;

      int yea1,yea2,mon1,mon2,day1,day2;
      int *p;

      long jia_day1=0;
      long jia_day2=0;
      long jia_day3=0;
      long jia_day4=0;
      long jia_all=0;

      printf("请输入第一个年月份 ");
      scanf("%d %d %d",&yea1,&mon1,&day1);
      printf("请输入第二个年月份 ");
      scanf("%d %d %d",&yea2,&mon2,&day2);
      if(judge(yea1))  printf("%d是闰年 ",yea1);
      if(judge(yea2))  printf("%d是闰年 ",yea2);
    if(yea1>yea2)
    { if(judge(yea2)) p=month2;
          else p=month1;
           jia_day1=*(p+mon2-1)-day2;
              for(i=mon2;i<=11;i++)
               jia_day2=jia_day2+*(p+i);
              for(i=yea2+1;i<yea1;i++)
                 jia_day3=jia_day3+allday(i);
        if(judge(yea1)) p=month2;
        else p=month1;
           for(i=1;i<mon1;i++)
               jia_day4=jia_day4+*(p+i-1);
           jia_all=jia_day1+jia_day2+jia_day3+jia_day4+day1;
           printf("%d%d%d比%d%d%d迟%d天 ",yea1,mon1,day1,yea2,mon2,day2,jia_all);
       }
    else if(yea1<yea2)
    { if(judge(yea1)) p=month2;
       else p=month1;
           jia_day1=*(p+mon1-1)-day1;
              for(i=mon1;i<=11;i++)
               jia_day2=jia_day2+*(p+i);
              for(i=yea1+1;i<yea2;i++)
                 jia_day3=jia_day3+allday(i);
         if(judge(yea2)) p=month2;
          else p=month1;
           for(i=1;i<mon2;i++)
               jia_day4=jia_day4+*(p+i-1);
           jia_all=jia_day1+jia_day2+jia_day3+jia_day4+day2;
           printf("%d%d%d比%d%d%d迟%d天 ",yea2,mon2,day2,yea1,mon1,day1,jia_all);
       }
    else
    { if(judge(yea1)) p=month2;
       else p=month1;
       if(mon1>mon2)
       {  jia_day1=*(p+mon2-1)-day2;
        for(i=mon2+1;i<mon1;i++)
        jia_day2=jia_day2+*(p+i-1);
         jia_all=jia_day1+jia_day2+day1;
        printf("第一个时间比第二个时间迟%d天 ",jia_all);
        }
     else if(mon1<mon2)
     {   jia_day1=*(p+mon1-1)-day1;
      for(i=mon1+1;i<mon2;i++)
        jia_day2=jia_day2+*(p+i-1);
         jia_all=jia_day1+jia_day2+day2;
        printf("第一个时间比第二个时间早%d天 ",jia_all);
        }
     else
        {if(day1>day2)
            printf("第一个时间比第二个时间迟%d天 ",(day1-day2));
         else if(day1<day2)
            printf("第一个时间比第二个时间早%d天 ",(day2-day1));
          else printf("这俩个时间相等 ");
        }
     }
    }

int allday(int x)
{ int y;
  if(((x%4==0)&&(x%100!=0))((x%100==0)&&(x%400==0)))
  {y=366;  printf("在这俩个数据中:%d是闰年 ",x);}
 else y=365;
  return (y);
}

相关内容
赞助商链接