答案:#include"stdio.h"
#include"string.h"
/*美化设计,主要输出格式 需要传入2个参数month和year,作用是输出格式*/
Shezhichushi(int month,long year)
{
char week[7][10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
if(1==month)printf("%36dyear\n",year);
printf("%35dmonth\n",month);
printf("%10s%10s%10s%10s%10s%10s%10s\n",week[0],week[1],week[2],week[3],week[4],week[5],week[6]);
}
/*返回一个值,如果是闰年的话,这个值就+1,有几次加几次,基准点为2000*/
exccedyear(long year)
{
int excced=0;
int i=0,j=0; /*j为加数,判断不是闰年的话,+1*/
excced=year-2000;
for(i=0;i<=excced;i++)
{
int f1=0,f2=0,f3=0;
f1=((year%4)==0);
f2=((year%100)==0);
f3=((year%400)==0);
if(f1&&(!f2)||f2&&f3)
j++;
else
; /*空操作*/
year--;
}
return j;
}
/*判断是否是闰年,是的话返回1,不是的话返回0,需要参数year*/
judgeyear(long year)
{
int i=0;
int f1=0,f2=0,f3=0;/*存储能否被4 100 400整除的逻辑值 */
f1=((year%4)==0);
f2=((year%100)==0);
f3=((year%400)==0);
if(f1&&(!f2)||f2&&f3) /*判断是否闰年*/
i=1;/*是闰年*/
else
i=0; /*不是闰年*/
return i;
}
/*对齐操作 输入多个空格 传入参数为kongcz 作用为对齐个数 */
Shurukongcz(int kongcz)
{
int i;
for(i=0;i<kongcz;i++)
printf(" ");
return kongcz;
}
Shuchu(int month,int judge,int year,int overtop)
{
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int t=0,/*现在的时间*/w=0;
w=Shurukongcz(Kongczzhi(month,judge,year,overtop))+1;
if(1==judge)day[2]=29;
for(t=1;t<=day[month];t++,w++)
{
printf("%10d",t);
if(0==(w%7))
printf("\n");
}
printf("\n");
return (w%7);
}
confirmchenyu(int year,int overtop)
{
int w=5;
int incept=0;
if((year>2000)&&(1==judgeyear(year))) overtop-=1;
if((incept=year-2000)>0);
w=365*(incept)+overtop+5;
return (w%7);
}
Kongczzhi(int month,int judge,int year,int overtop)
{
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int w=confirmchenyu(year,overtop);
int i=1;
if(1==judge)day[2]=29;
for(i=1;i<month;i++)
{
w+=day[i];
}
return w%7;
}
main()
{
int overtop=0;
int judge=0;
int month=1;
long year=2000;
char in='N';
do
{
printf("please input vintagequz(greater than 2000,else exit)");
scanf("%d",&year);
while(year<2000)
{
printf("Are you sure you want to exit Y/N");
in=getchar();
while(in!='Y'&&in!='N')
in=getchar();
if('Y'==in)
{
exit(0);
}
else
{
printf("please input vintagequz(greater than 2000,else exit)");
scanf("%d",&year);
}
}
judge=judgeyear(year);
overtop=exccedyear(year);
for(month=1;month<=12;month++)
{
Shezhichushi(month,year);
Shuchu(month,judge,year,overtop);
getch();
}
}while(year>=2000);
}
上一个:C++应该怎样学?学了做什么?
下一个:c++课程设计 高分急求高手解答