//1.判断闰年的函数
int run(int year)
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else
return 0;
}
//2.每月的天数
int getday(int year,int mon)
{
int days;
switch(mon)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:days=31;break;
case 4:
case 6:
case 9:
case 11:days=30;break;
case 2: if(run(year)==1)
days=29;
else
days=28;
break;
}
return days;
}
//3.计算闰年个数
int getruns(int year)
{
int i,runs=0;
for(i=1900;i<year;i++)
{
if(run(i)==1)
runs++;
}
return runs;
}
//4.计算整年天数
int getzheng(int year)
{
int zheng;
zheng=365*(year-1900)+getruns(year);
return zheng;
}
//5.计算不整年天数
int getbuzh(int year,int mon)
{
int bzh;
switch(mon)
{
case 1:bzh=1;break;
case 2:bzh=31+1;break;
case 3:bzh=31+28+1;break;
case 4:bzh=31*2+28+1;break;
case 5:bzh=31*2+30+28+1;break;
case 6:bzh=31*3+30+28+1;break;
case 7:bzh=31*3+30*2+28+1;break;
case 8:bzh=31*4+30*2+28+1;break;
case 9:bzh=31*5+30*2+28+1;break;
case 10:bzh=31*5+30*3+28+1;break;
case 11:bzh=31*6+30*3+28+1;break;
case 12:bzh=31*6+30*4+28+1;break;
}
if(run(year)==1)
{
if(mon>=3)
bzh+=1;
}
return bzh;
}
//6.计算总天数
int getzong(int year,int mon)
{
int zong;
zong=getzheng(year)+getbuzh(year,mon);
return zong;
}
//7.计算星期
int getwk(int year,int mon)
{
int wk;
wk=getzong(year,mon)%7;
return wk;
}
//8.打印字符
void print_char(int x,char ch)
{
int i;
for(i=1;i<=x;i++)
{
printf("%c",ch);
}
}
//9.打印结果
void print_mon(int year,int mon)
{
int i,m;
int wk=getwk(year,mon);
int days=getday(year,mon);
printf("\t\t\t%d年%d月\n",year,mon);
print_char(50,'=');
printf("\n");
printf("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n");
print_char(wk,'\t');
m=wk;
for(i=1;i<=days;i++)
{
printf("%d\t",i);
m++;
if(m%7==0)
printf("\n");
}
printf("\n");
}
//10.打印年历?
//11.定义一个函数判断成绩是否及格
int check(float s)
{
if(s>=60)
return 1;
else
return 0;
}
评论0
最新资源