#include
#include
int c,week=0,p;
FILE *fp;
int dyear(int year)
{
int leap;
leap=(year%4==0&&year%100!=0)||year%400==0;
return leap;
}
int day_of_year(int year,int month,int day)
{
int k,leap;
int tab[2][12]={
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}
};
leap=dyear(year);
for(k=0;k
return day;
}
int days(int syear) //利用已知的日期生成日期
{
int smonth,sday,eyear,emonth,eday,d=0;
smonth=1,sday=1;
while(1)
{
eyear=2010,emonth=4,eday=25,week=0; //已知日期
p=syear-eyear;
if(eyear>=syear)
{
d=day_of_year(eyear,emonth,eday)-day_of_year(eyear,smonth,sday)+1;
while(eyear>syear)
{
if(dyear(syear)!=0)
d=d+366;
else
d=d+365;
syear++;
}
}
else
{
if(dyear(eyear)!=0)
d=366-day_of_year(eyear,emonth,eday)+1;
else d=365-day_of_year(eyear,emonth,eday)+1;
while(syear>eyear+1)
{
if(dyear(eyear)!=0)
d=d+366;
else
d=d+365;
eyear++;
}
}
break;
}
return d;
}
void print()
{
int d,t,k=0,r,i,j,leap,syear;
int tab[2][12]={
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
if((fp=fopen("日历.txt","w"))==NULL)
printf("打开文件失败!");
printf("\n输入你要查询的年份:(-)");
scanf("%d",&syear);
fprintf(fp,"你查询的年份是-%d年",syear);
leap=dyear(syear);
d=days(syear);
if(d==0) //恰好输入的是预设的日期
t=week;
else
{
if(p>0)
{
if(d%7==0)
t=(week+7)%7;
else
t=(week+d%7-1)%7+1;
}
else
{
if(d%7==0)
t=(week+1)%7;
else t=(8-(d%7-week))%7;
}
}
for(i=0;i<12;i++)
{
printf("\n\n %d月",i+1);
fprintf(fp,"\n\n %d月",i+1);
printf("\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n");
fprintf(fp,"\n-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n");
printf("\n日\t一\t二\t三\t四\t五\t六\n");
fprintf(fp,"\n日\t一\t二\t三\t四\t五\t六\n");
for(r=0;r<8*t;r++) //控制的输入的首行星期几
{
printf(" ");
fprintf(fp," ");
}
for(j=1;j<=tab[leap][i];j++)
{
printf("%d\t",j);
fprintf(fp,"%d\t",j);
k++;
if((t+k)%7==0)
{
printf("\n");
fprintf(fp,"\n");
k=0,t=0;
}
}
t=k,k=0;
getch();
}
fclose(fp);
}
int main()
{
print();
return 0;
}
给你源码吧,外加文件操作。报告你要自己写。