网上找的部分带我,我又修改了一下,现在基本满足lz的要求。
手头没有Wintc用vc测的,不过没用到什么vc特有的东西,应该可以的。
#include
#include
#include
void DayOfWeek()
{
int rtnDay;
int y,m,d;
char ch;
while (1)
{
printf("请输入年月日(xxxx,xx,xx): ");
scanf("%d,%d,%d", &y, &m, &d);
fflush(stdin);
rtnDay = (3*y-(7*(y+(m+9)/12))/4+(23*m)/9+d+17-((y+(m<3?-1:0))/100+1)*3/4) % 7;
printf("%04d年%02d月%02d日 是 星期%d\n", y, m, d, rtnDay?rtnDay:7);
printf("继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetMonth(int D, int md, int n)
{
int N ,m,d,y,c,Wd;
int i,maxday,i1;
if(md>=13||md<=0)
printf("HAVE WRONG!");
else
{
for(i1=0;;md++,i1++)
{
if(md==0)
{
md=12;
D-=1;
}
else
if(md==13)
{
md=1;
D+=1;
}
m=md;
printf("\n============%d,%2d============\n",D,md);
if(0
switch(m)
{
case 1:maxday=31;break;
case 2:if(D%4==0&&D%100!=0||D%400==0)
maxday=29;
else
maxday=28;
break;
case 3:maxday=31;break;
case 4:maxday=30;break;
case 5:maxday=31;break;
case 6:maxday=30;break;
case 7:maxday=31;break;
case 8:maxday=31;break;
case 9:maxday=30;break;
case 10:maxday=31;break;
case 11:maxday=30;break;
case 12:maxday=31;break;
default:printf("HAVE WRONG");
}
if(0
N=D-1;
m=m+10;
}
else
{
N=D;
m=m-2;
}
c=N/100;
y=N%100;
Wd=((1+(13*m-1)/5+y+y/4+c/4-2*c)%7+7)%7;
printf(" SUN MOU TUE WED TUR FRI SAT\n");
for(i=0;i
for(d=1;d<=maxday;d++)
{
printf("%4d",d);
Wd=(Wd+1)%7;
if(Wd==0)
printf("\n");
}
}
else
printf("HAVE WRONG!");
if(i1==n)
break;
}
}
}
void MonthOfYear()
{
char ch;
int y, m;
while (1)
{
printf("请输入年月(xxxx,xx): ");
scanf("%d,%d", &y, &m);
fflush(stdin);
GetMonth(y, m, 0);
printf("\n继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetYear()
{
char ch;
int y;
while (1)
{
printf("请输入年: ");
scanf("%d", &y);
fflush(stdin);
GetMonth(y, 1, 11);
printf("\n继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
int main()
{
char ch;
while(1)
{
system("cls");
printf("1.查询星期\n");
printf("2.查询月份\n");
printf("3.显示一年\n");
printf("4.退出程序\n");
ch = getchar();
fflush(stdin);
switch(ch)
{
case '1':
DayOfWeek();
break;
case '2':
MonthOfYear();
break;
case '3':
GetYear();
break;
case '4':
printf("是否退出(y/n)");
ch = getchar();
fflush(stdin);
if(ch == 'y' || ch == 'Y')
exit(0);
break;
}
}
}
另外,虚机团上产品团购,超级便宜