- UID
- 65325
注册时间2010-2-1
阅读权限20
最后登录1970-1-1
以武会友
TA的每日心情 | 郁闷 2017-1-19 11:18 |
---|
签到天数: 6 天 [LV.2]偶尔看看I
|
本帖最后由 komany 于 2010-12-8 12:16 编辑
- #include "stdio.h"
- void main()
- {
- int leap_year(int y);
- int count_leap(long year);
- int monthdays(int month,long year);
- void monthprint(long year,int month);
- int month=0;
- long int year=0;
- char choose;
- clrscr();
- do
- {printf ("\n\nPlease input one integer number as 'year'(0~3000):\n");
- scanf ("%ld",&year);
- if (year<0||year>3000) printf ("ERROR,please input again!");
- }
- while (year<0||year>3000);
- printf ("\n\n");
- do
- {printf ("please input the month(1~12)\n\n");
- scanf ("%d",&month);
- if (month<=0||month>12) printf ("please input again!");
- }
- while (month<=0||month>12);
- printf ("\n\n\n");
- printf("\t\t\t\t%ld\t%d\n\n",year,month);
- printf
- ("\n********************************************************************************\n");
- printf("\t\t Sun\t Mon\t Tue\t Wen\t Thu\t Fri\t Sat\n");
- monthprint(year,month);
- printf("\n\n");
- }
- int leap_year(int y)
- { int i;
- if (y%4==0&&y%100!=0||y%400==0) i=1;
- else i=0;
- return i;
- }
- //多谢N大的教导,下面/**/的里面是N大优化的代码
- /*int leap_year(int y)
- {
- return (!(y%4)&&y%100 )|| !(y%400) ;
- }
- */
- int count_leap(long year)
- {
- int i=0,j,min,max;
- if(year>2006) {min=2006;max=year;}
- else {min=year+1;max=2006;}
- for(j=min;j<max;j++)
- if(leap_year(j)) i++;
- return i;
- }
- int monthdays(int month,long year)
- {
- int sum=0,i,j;
- if(year>=2006)
- { int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
- j=month-1;
- if(leap_year(year)) t[1]=29;
- else t[1]=28;
- for(i=0;i<j;i++)
- sum=sum+t[i];
- }
- else
- { int t1[12]={31,30,31,30,31,31,30,31,30,31,0,31};
- j=12-month;
- if(leap_year(year)) t1[10]=29;
- else t1[10]=28;
- for(i=0;i<=j;i++)
- sum=sum+t1[i];
- }
- return sum;
- }
- void monthprint(long year,int month)
- {
- int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
- int i,y,weekday=0;
- long days=0;
- if(leap_year(year)) t[1]=29;
- else t[1]=28;
- y=t[month-1];
- if(year>2006)
- {
- days=(year-2006)*365+count_leap(year)+monthdays(month,year);
- weekday=days%7;
- }
- else if(year<2006)
- {days=(2005-year)*365+count_leap(year)+monthdays(month,year);
- weekday=7-days%7;
- }
- else
- {days=monthdays(month,year);weekday=days%7;}
- for (i=1;i<=weekday+2;i++)
- printf ("\t");
- for (i=1;i<=y;i++)
- {if ((i+weekday-1)%7==0) printf ("\n\n\t\t%3d\t",i);
- else printf ("%3d\t",i);};
- printf
- ("\n********************************************************************************\n\n");
- }
复制代码 |
|