用c语言编制一个万年历
发布网友
发布时间:2022-04-29 08:38
我来回答
共2个回答
热心网友
时间:2022-06-24 23:34
大姐。。没有money的活儿。。
我可不干。
为了 一口气。。呵呵。。
模块化的思想
#include<stdio.h>
#include<windows.h>
#include<dos.h>
int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
char weekday[7][7]={"一","二","三","四","五","六","七"};
int week(int y,int m,int d)
{
int day=0;
day=days[m-1]+d-1;
return (y-1+(y-1)/4-(y-1)/100+(y-1)/400+day)%7;
}
void print()
{
puts("*************************万年日历***************************");
puts("1.Week");
puts("2.Month");
puts("3.Calendar");
puts("4.Exit");
printf("您选择的是:");
}
void printmonth(int y,int m)
{
int i,j,w;
w=(week(y,m,1)+1)%7;
puts(" SUN MON TUE WED THU FRI SAT");
for(i=1;i<=w;i++)
printf("%5c",' ');
for(j=i;j<i+month[m-1]+(m==2&&(y%4==0&&(y%100)||y%400==0));j++)
{
printf("%5d",j-i+1);
if(j%7==0)
puts("");
}
if((j-1)%7)
puts("");
}
int printweek()
{
int y,m,d;
char temp[1];
system("cls");
puts("请输入年月日, 格式如:2012 12 25");
printf("年月日为:");
scanf("%d%d%d",&y,&m,&d);
printf("\n%4.4d年%2.2d月%2.2d日 是星期%s\n\n是否继续查询(Y/N)? ",y,m,d,weekday[week(y,m,d)]);
scanf("%s",temp);
while(1){
if(temp[0]=='N' || temp[0]=='n')
return 0;
else if(temp[0]=='y' || temp[0]=='Y')
printweek();
else
puts("输入错误!请输入n/y");
scanf("%s",temp);
}
return 0;
}
int printmonth2()
{
int y,m;
char temp[1];
system("cls");
puts("请输入要打印的年份/月份,格式如:2012 12");
printf("年月为: ");
scanf("%d%d",&y,&m);
printf(" %4.4d年%2.2d月\n",y,m);
printmonth(y,m);
printf("是否继续查询(Y/N)?");
scanf("%s",temp);
while(1){
if(temp[0] =='N' || temp[0] =='n')
return 0;
else if(temp[0]=='Y' || temp[0]=='y')
printmonth2();
else
puts("输入错误 !请输入y/n");
scanf("%s",temp);
}
return 0;
}
int printcalender()
{
int y,i;
char temp[1];
system("cls");
puts("请输入要打印的年份,格式如:2012");
printf("年份为: ");
scanf("%d",&y);
printf(" %4.4d\n",y);
for(i=1;i<=12;i++)
{
printf(" %2.2d月份\n",i);
printmonth(y,i);
}
printf("是否继续查询(Y/N)?");
scanf("%s",temp);
while(1)
{
if(temp[0]=='N' || temp[0]=='n')
return 0;
else if(temp[0]=='Y' || temp[0]=='y')
printcalender();
else
puts("输入错误!请输入y/n");
scanf("%s",temp);
}
return 0;
}
int exit1()
{
char temp[1];
system("cls");
printf("是否要真的退出(Y/N)? ");
scanf("%s",temp);
while(1){
if(temp[0]=='y' || temp[0]=='Y')
puts("bye_bye");
exit(0);
else if(temp[0]=='n' || temp[0]=='N')
return 0;
else
puts("输入错误!请输入y/n");
scanf("%s",temp);
}
return 0;
}
int main(void)
{
int temp;
print();
scanf("%d",&temp);
while(1)
{
if(temp==4)
exit1();
switch(temp)
{
case 1:
printweek();
break;
case 2:
printmonth2();
break;
case 3:
printcalender();
break;
default:
printf("请入输入正确的选项\n");
system("pause");
break;
}
system("cls");
print();
scanf("%d",&temp);
}
return 0;
}
热心网友
时间:2022-06-24 23:35
#include<stdio.h>
//#include<windows.h>
int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
char weekday[7][7]={"一","二","三","四","五","六","七"};
int week(int y,int m,int d)
{
int day=0;
day=days[m-1]+d-1;
return (y-1+(y-1)/4-(y-1)/100+(y-1)/400+day)%7;
}
void print()
{
puts("1.Week");
puts("2.Month");
puts("3.Calendar");
puts("4.Exit");
}
void printmonth(int y,int m)
{
int i,j,w;
w=(week(y,m,1)+1)%7;
puts(" SUN MON TUE WED THU FRI SAT");
for(i=1;i<=w;i++)
printf("%5c",' ');
for(j=i;j<i+month[m-1]+(m==2&&(y%4==0&&(y%100)||y%400==0));j++)
{
printf("%5d",j-i+1);
if(j%7==0)
puts("");
}
if((j-1)%7)
puts("");
}
int main()
{
int i,y,m,d,c;
char op[1];
print();
while(scanf("%d",&c)==1)
{
if(c==1)
{
do
{
puts("请输入年月日(XXXX,XX,XX)");
scanf("%d%d%d",&y,&m,&d);
printf("%4.4d年%2.2d月%2.2d日是星期%s,是否继续查询(Y/N)?\n",y,m,d,weekday[week(y,m,d)]);
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==2)
{
do
{
puts("请输入要打印的月份(XXXX)");
scanf("%d%d",&y,&m);
printf(" %4.4d年%2.2d月\n",y,m);
printmonth(y,m);
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==3)
{
do
{
puts("请输入要打印的年份(XXXX)");
scanf("%d",&y);
printf(" %4.4d\n",y);
for(i=1;i<=12;i++)
{
printf(" %2.2d月\n",i);
printmonth(y,i);
}
puts("是否继续打印(Y/N)?");
scanf("%s",op);
}while(op[0]=='Y');
print();
}
if(c==4)
{
puts("是否要真的退出(Y/N)?");
scanf("%s",op);
if(op[0]=='Y')
return 0;
else print();
}
}
}