万年历。。。
本帖最后由 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?or");
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 \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);
} int leap(int year)
{
return ((year%4&&year%100)||year%400)
} 过来顶z大的文章 过来顶z大的文章
whypro 发表于 2010-12-4 21:51 https://www.chinapyg.com/images/common/back.gif
你在顶Z大一个跟头/:017 int leap(int year)
{
return ((year%4&&year%100)||year%400)
}
komany 发表于 2010-12-4 21:50 https://www.chinapyg.com/images/common/back.gif
嗯,确实。改了。 本帖最后由 whypro 于 2010-12-5 07:39 编辑
回复 4# komany
??k大你真是太纠结了! 回复komany
??k大你真是太纠结了!
whypro 发表于 2010-12-5 07:38 https://www.chinapyg.com/images/common/back.gif
why大真是起的比鸡早,睡的比小姐晚。
模范啊!! 瞅瞅z大怎么实现的 额,阅读权限不够,没天理啊!呜呜...... 我也来膜拜一下~!
页:
[1]
2