QQ网名大全

万年历查询程序 功能要求: (1)提供菜单方式选择 (2)输入年份、月份、日期,计算得到的是这一天

计算得到的这一天是星期几吗?? 还是?/* welcome to use the wannianli system! */
#include<stdio.h>
#include<stdlib.h>
char* month_str[]={"january","february","march","april","may","june","july","august","september","october","november","december"};
char* week[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};

int leap (int year)//判断闰年
{
if(year%4==0&&year%100!=0||year%400==0)
return 1;
else return 0;
}
int month_day(int year,int month) //判断这一个月有多少天
{
int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; //初始化每个月的天数
if(leap(year)&&month==2 )
return 29;
else
return(mon_day[month-1]);

}
int firstday(int year,int month,int day)//判断这一个月的第一天是星期几
{
int c=0;
float s;
int m;
for(m=1;m<month;m++)
c=c+month_day(year,m);
c=c+day;
s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;
return ((int)s%7);
}
int printallyear(int year)/*print the all year*/
{
int a,b;
int i,j=1,n=1,k;
for(k=1;k<=12;k++)
{
j=1,n=1;
b=month_day(year,k);
a=firstday(year,k,1);
printf("\n\n%s(%d)\n",month_str[k-1],k);
printf(" sun mon tue wed thu fri sat \n**************");
if(a==7)
{
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i%7==0)
{
printf("**************\n**************");
}
}
}
if(a!=7)
{
while (j<=4*a)
{
printf(" ");
j++;
}
for(i=1;i<=b;i++)
{
printf("%4d",i);
if(i==7*n-a)
{
printf("**************\n**************");
n++;
}
}
}
printf("**************\n");
}
return 1;
}
int main()
{
int option,da;
char ch;
int year,month,day;
while(1)
{
printf("\n请选择你所需要的服务:\n");
printf("\n输入1求某个日期对应的星期");
printf("\n输入2结束程序\n");
scanf("%d",&option);
switch(option)
{
case 1:
while(1)
{
printf("\nplease input the year,month and day(xxxx,xx,xx):");
scanf("%d,%d,%d,%c",&year,&month,&day);
da=firstday(year,month,day);
printf("\n%d-%d-%d ** %s,do you want to continue?(y/n)",year,month,day,week[da]);
fflush(stdin);
scanf("%c",&ch);
if(ch=='n'||ch=='n')
break;
}
break;
case 2:
fflush(stdin);
printf("are you sure?(y/n)");
scanf("%c",&ch);
if(ch=='y'||ch=='y')
exit(0);
break;
default:
printf("\nerror:sorry,there ** no th** service now!\n");
break;
}
}
return 0;
}
佚名
2024-12-23 14:07:24
最佳回答
类似问题(10)