- UID
- 59317
注册时间2009-1-28
阅读权限40
最后登录1970-1-1
独步武林
TA的每日心情 | 无聊 2024-1-15 22:57 |
---|
签到天数: 3 天 [LV.2]偶尔看看I
|
本帖最后由 zaas 于 2010-12-6 21:09 编辑
- #include <stdio.h>
- int leap(int year);
- int check(int year,int month,int day);
- int getweek(int year,int month);
- int showmonth(int year,int month);
- void print(int year,int month,int day,int weekday);
- void main()
- {
- int year,month,day,weekday;
- char key;
- while(1)
- {
- printf("Please input Year-Month-Day(eg: 2012-12-31):");
- scanf("%d-%d-%d",&year,&month,&day);
- getchar();
- if (!check(year,month,day))
- {
- weekday=getweek(year,month);
- print(year,month,day,weekday);
- }
- else
- {
- printf("Wrong input!\n");
- }
- printf("Continue?[Y]or[N]");
- scanf("%c",&key);
- getchar();
- if (key!='y'&& key !='Y')
- {
- break;
- }
- }
- }
- int leap(int year)
- {
- return(!((year%4)&&(year%100))||!(year%400));
- }
- int check(int year,int month,int day)
- {
- int i,mark=0;
- if (year<1901||year>3000 || month<1 || month>12 || day<1 || day>31 )
- {
- mark=1;
- }
- if (month==4||month==6||month==9||month==11)
- {
- if (day>30)
- {
- mark=1;
- }
- }
- else if(month==2)
- {
- i= (leap(year))?29:28;
- if (day>i)
- {
- mark=1;
- }
- }
- return (mark);
- }
- void print(int year,int month,int day,int weekday)
- {
- int i,k,dayofmonth;
- dayofmonth=showmonth(year,month);
- printf("my calender [code by zaas]\n\n");
- printf("date:%4d-%2d\n\n",year,month);
- printf("SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n");
- printf("-----------------------------------------------------\n");
- for (i=0;i<weekday;i++)
- {
- printf("\t");
- }
- for (i=1;i<=dayofmonth;i++)
- {
- k=weekday+i-1;
- if (i==day)
- {
- printf("[%2d]\t",i);
- }
- else
- {
- printf("%3d\t",i);
- }
- if (k%7==6)
- {
- printf("\n-----------------------------------------------------\n");
- }
- }
- printf("\n-----------------------------------------------------\n\n");
- }
- int showmonth(int year,int month)
- {
- int m=31;
- if(month==4||month==6||month==9||month==11)
- {
- m=30;
- }
- else if(month==2)
- {
- m=(leap(year))?29:28;
- }
- return(m);
- }
- int getweek(int year,int month)
- {
- int i,totalday=0;
- for (i=1900;i<year;i++)
- {
- totalday+=(leap(i))? 366:365;
- totalday=totalday%7;
- }
- for(i=1;i<month;i++)
- {
- totalday+=showmonth(year,i);
- }
- return((totalday)%7);
- }
复制代码 |
评分
-
参与人数 1 | 威望 +80 |
飘云币 +400 |
收起
理由
|
兔小样
| + 80 |
+ 400 |
您的贴子很精彩,希望能再次分享! |
查看全部评分
|