Chinaunix首页 | 论坛 | 博客
  • 博客访问: 372807
  • 博文数量: 84
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 940
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-12 20:30
文章分类

全部博文(84)

文章存档

2010年(18)

2009年(27)

2008年(39)

我的朋友

分类: C/C++

2009-03-29 14:22:37

/*忘了写此程序的有效期是1900年后,有好多可能没有写明白 */
#include
#include
static int day_tab[2][13]=
                  {{0,31,28,31,30,31,30,31,31,30,31,30,31},
                  {0,31,29,31,30,31,30,31,31,30,31,30,31}};
struct date {
       int year;
       int month;
       int day;
       };
 int days(struct date day)
         {  
         int i,lp;
         lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
           /* lp 非0为闰年*/
         for(i=1;i             day.day+=day_tab[lp][i]; /*计算本年中1月1日起的天数*/  
         return(day.day);
        }  
int main()
{ struct date today,term;
  int year,day,i,x,j;  
  unsigned int yearday;
    while (1){
  printf("\nEnter year/month/day:");
  scanf("%d/%d/%d",&today.year,&today.month,&today.day);
  //monthday=today.day  
  term.month=12;
  term.day=31;
  for (yearday=0,year=1900;year      { term.year=year;
        yearday +=days(term);       /*计算今年前的总天数*/  
       }
       yearday +=days(today)-today.day+1;  
       day=yearday%7;                     /*算这个月1日是星期几*/  
       //printf(" This date is %ds ",day);
       x= today.year%4==0&&today.year%100!=0||today.year%400==0;
    if(today.year<1900 ||today.month<1||today.month>12||today.day<1 ||today.day>day_tab[x][today.month])
    { printf("输入的日期格式错误\n");
        exit(1);
    }
       printf("------------------------------\n");
       printf(" Sun Mon Tue Wed Thu Fri Sat \n");    /*打印日历*/  
       
       for(j=0;j       for(++j,i=1;i<=day_tab[x][today.month];i++,j++)   /*打印当月的总天数*/ 
        { /* if (i==today.day) printf("  \1 "); 
              else*/
             printf("%4d",i); 
           if (j%7==0) printf("\n");  /*控制日历格式打印*/ 
           }
        printf("\n");
     }
       return 0; 
       } 
        
                                                   
阅读(1937) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

maonx2009-04-01 20:34:53

? 上面忘了备注有效时间是1900以后

chinaunix网友2009-04-01 18:48:45

1700.2.29 1752.9.3-1752.9.13