小学生免费资源谁有-卤代烃命名
2022年11月16日发(作者:肖卓能的个人资料)#include
#include
#include
#include
char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char *strmonth[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Set","Oct","Nov","Dec"};
int dayofyear[2]={365,366};
int dayofmonth[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} };
int isleapyear(int year) /*判断是否是闰年 闰年返回 1*/
{
if(0==year%100&&0==year%400||0!=year%100&&0==year%4)
return 1;
el
return 0;
}
int alldays(int y,int m) /* 公元一月一号到公元某年某月的总天数 */
{
int a,b,c=0;
for(a=m;a>1;a--)
c=c+dayofmonth[isleapyear(y)][a-2];
for(b=1;b
c=c+dayofyear[isleapyear(b)];
return c;t t
}
void outputtoscreen(int year,int month,int w) /* 改 月历输出到屏幕 */
{
int j,k;
printf("
*****第%d年***第%d月*****
",year,month);
printf(" 日 一 二 三 四 五 六
");
for(j=0;j
printf(" ");
for(k=1;k<=dayofmonth[isleapyear(year)][month-1];k++)
{tprintf("%4d",k);
if((k+w)%7==0)t printf("
");
}t
}
int onemonth()
{
int i,w;
int year,month;
printf("
");
printf("t要查询的年份月份:");
scanf("%d%d",&year,&month);
if(year>0)
i=alldays(year,month);
el
{
printf("error
");
getch();
return(0);
}
w=i%7;
outputtoscreen(year,month,w);
getch();
}
int oneyear()
{ FILE *fp;
int date[24][21],n,kk,k,w[12],i,j,year;
printf("t请输入要查询的年份:");
scanf("%d",&year);
w[0]=(alldays(year-1,12)+1)%7;
kk=isleapyear(year);
for(i=0;i<24;i++)
for(j=0;j<21;j++)
date[i][j]=0;
for(i=1;i<12;i++)
w[i]=(w[i-1]+dayofmonth[kk][i-1])%7;
for(j=0;j<12;j++)
{ n=0;
for(i=1;i<=dayofmonth[kk][j];i++)
{ date[(j/3)*6+n][(j%3)*7+w[j]]=i ;
w[j]++;
if(w[j]==7) { w[j]=0; n++; }
}
}
fp=fopen("c:","w");
fprintf(fp,"
************************************** %d",year);
fprintf(fp," ***************************************
");
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{ fprintf(fp,"%4s",strmonth[i*3+j]);
fprintf(fp,"%28s"," "); }
fprintf(fp,"
");
for(j=0;j<3;j++)
{ for(k=0;k<7;k++)
fprintf(fp,"%4s",wday[k]);fprintf(fp," "); }
fprintf(fp,"
");
for(j=0;j<6;j++)
{ for(k=0;k<21;k++)
{ if(date[i*6+j][k]==0) fprintf(fp," ");
el fprintf(fp,"%4d",date[i*6+j][k]);t
if(k==6||k==13) fprintf(fp," "); }
fprintf(fp,"
");
}
}
fclo(fp);
}
void countof2date() /*输入未来某
天的日期,输出距今天还有多少天,是星期几*/
{ int i,c,tmp,date[2][5];
time_t timep;
struct tm *p;
time(&timep);
p=localtime(&timep); /*取得当地时间*/
date[0][0]=1900+p->tm_year; /* 年 */
date[0][1]=1+p->tm_mon; /* 月 */
date[0][2]=p->tm_mday; /* 日 */
date[0][3]=p->tm_wday; /* 周 */
date[0][4]=1+p->tm_yday; /* 第几天 */
printf("
t请输入未来时间(格式为 年 月 日 ):");
scanf("%d%d%d",&date[1][0],&date[1][1],&date[1][2]);
tmp=isleapyear(date[1][0]);
c=date[1][2];
c-=date[0][4];
for(i=1;i
c+=dayofmonth[tmp][i-1];
for(i=date[0][0];i
c+=dayofyear[isleapyear(i)];
date[1][3]=(date[0][3]+c)%7;
printf("距今天还有:%d天,是: %s
",c,wday[date[1][3]]);
getch();t
}
void menu()
{ int choice;t
do
{ system("cls");
printf("
");
printf("tt请输入选项:
");
printf("**1:输入未来某天的日期,输出距今天还有多少天,是星期几
");
printf("**2:打印年历
");
printf("**3:打印月历
");
printf("**0:退出
"); t
printf("您要查询的内容是:");
scanf("%d",&choice);
switch(choice)
{ ca 1:countof2date();break;
ca 2:oneyear();break;
ca 3:onemonth();break;
}
}while(choice!=0);t
}
main()
{
printf("
tt******************************
");
printf("ttt欢迎使用!
");
printf("
tt******************************
");
printf("tttt按回车继续!
");
getchar();
menu();
}