求助,求助,求助,求助,求助,求助,求助
网上有了很多万年历,但是我想把月历改成年历得怎么改?以下是月历的C代码,希望大家帮帮忙.#include <stdio.h>
int findyear(int year)//判断闰年
{
return (year%4==0&&year%100!=0||year%100==0&&year%400==0? 1:0);
}
int CalWkd(int year,int mth)
{
int ds=0,i,rst,wkd;
int mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if (findyear(year))
mthd[2]=29;
for (i=1;i<mth;i++)
ds+=mthd[i];
ds+=1;
rst=year-1+(int)((year-1)/4)-(int)((year-1)/100)+(int)((year-1)/400)+ds;
wkd=rst%7;
return wkd;
}
showcld(int wkd,int mtd)
{
int dt=1,i,j=0;
printf("Sun\tMon\tTue\tWed\tThu\tFri\tSat\n");
for (i=0;i<wkd;i++)
{
printf("\t");
j++;
}
while (j!=7)
{
printf("%d",dt);
if (j<6)
printf("\t");
else
printf("\n");
dt++;
j++;
}
while (1)
{
for (j=0;j<7;j++)
{
printf("%d",dt);
if (j!=6)
printf("\t");
else
printf("\n");
if (dt!=mtd)
dt++;
else
return 0;
}
}
}
int main()
{
int year,mth,mtd,wkd,mthd[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
printf("Input the Year and Month(Year-Month):");
scanf("%d-%d",&year,&mth);
if (year<0||mth<1||mth>12)
return 0;
if (findyear(year))
mthd[2]=29;
mtd=mthd[mth];
wkd=CalWkd(year,mth);
showcld(wkd,mtd);
return 0;
}