QQ网名大全

c语言编写万年历~~速度

/*c语言编程万年历
要求输入年月,判断是否闰年;
输入年月日,判断星期几;
输入年份,打出12个月的月历;
输入年份,月份,打印出本月日历;
要求用多个函数实现。*/
#include<stdio.h>
#include<time.h>
#include<string.h>int calendar[12][6][7];/*月历*/
char* week[]={"sunday","monday","tuesday","wednesday","thursday","friday","satarday"};
char* monthname[]={"january","february","march","april","may","june","july",
"august","september","october","november","december"};
int monthday[]={31,28,31,30,31,30,31,31,30,31,30,31};
char* menu[]={/*操作菜单*/
"1.input a year number,check whether it's a leap year.\n",
"2.input year,month,day,check the weekday.\n",
"3.input year,month,output the calendar of that month.\n",
"4.input year,output all the month calendar.\n",
"0.exit.\n"
};/*判断参数year传递的年份是否是闰年*/
int **leapyear(int year)
{
if(!(year%4)&&year%100||!(year%400)) return 1;
else return 0;
}/*输入年月日,判断星期几,利用zeller公式w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
w是结果星期数,y是年份的后两位,c是年份的前两位,m是月份,3≤m≤14,也就是当
m≤2时,要算到前一年的13月份和14月份,最后要将w对7取模
*/
int weekday(int year,int month,int day)
{
int w,y,c,m,d;
c=year/100;
if(month<3){
m=12+month;
y=year%100-1;
}
else{
m=month;
y=year%100;
}
d=day;
w=y+y/4+c/4-2*c+26*(m+1)/10+d-1;
return (w%7+7)%7;
}/*输入年份,月份,打印出本月的日历*/
void monthly(int year,int month)
{
int weekday,i,j;
if(month==2)
if(**leapyear(year)) monthday[1]+=1;
weekday=weekday(year,month,1);
printf("%s\n",monthname[month-1]);
printf("sun. mon. tue. wed. thu. fri. sat.\n");
for(i=1,j=weekday;i<=monthday[month-1];i++,j++){
calendar[month-1][j/7][j%7]=i;
}
for(i=0;i<6;i++){
for(j=0;j<7;j++)
{
if(calendar[month-1][i][j]==0) printf("%5c",' ');
else printf("%-5d",calendar[month-1][i][j]);
}
printf("\n");
}
}void allmonth(int year) /*输入年份,打印出12个月的月历*/
{
int i;
for(i=1;i<=12;i++){
monthly(year,i);
getch();/*按任意键继续执行*/
}
}void main(void)
{
int year,month,day,i,n,weekday;
memset(&calendar,sizeof(calendar),0); /*初始化月历*/
for(i=0;i<5;i++)
printf("%s",menu[i]);
while(1){
printf("please choose the menu:");
scanf("%d",&n);
printf("\n");
switch(n){
case 1:
printf("please input year:");
scanf("%d",&year);
if(**leapyear(year)) printf("\n%d ** leap year.\n",year);
else printf("%d **n't leap year.\n",year);
break;
case 2:
printf("please input year month day:");
scanf("%d%d%d",&year,&month,&day);
printf("\n");
weekday=weekday(year,month,day);
printf("that day ** %s\n",week[weekday]);
break;
case 3:
printf("please input year month,then it output a calendar of that month:");
scanf("%d%d",&year,&month);
printf("\n");
monthly(year,month);
break;
case 4:
printf("please input year,then it will output the calendar of that year:");
scanf("%d",&year);
printf("\n");
allmonth(year);
break;
case 0:
return;
default:
printf("the number you input ** invalid.\n");
break;
}
}
getch(); /*按任意键,程序退出*/
}这个程序是可用的~~希望能帮到你~~~
佚名
2024-06-01 10:49:53
最佳回答
类似问题(10)
  • 佚名
    2024-06-01 11:44:56

    单片机c语言万年历设计

    呵呵,这个东西我最近做过。也用过ds1302、pcf8563时钟芯片,还算比较简单啦。只不过没这么多功能,这些日子正想做个跟手表一样多的功能。等做完了,发给你把...

  • 佚名
    2024-06-01 22:40:33

    编写万年历c语言高手进

    #include <stdio.h>#include <stdlib.h>#define true 1enum{sunday, monday, tu...

  • 佚名
    2024-06-01 18:59:44

    c语言万年历程序设计

    功能要求:模仿现实生活中的挂历. 当前页以系统当前日期的月份为准显...答:#include int leap (int year) {if(year%4==0...

  • 佚名
    2024-06-01 08:00:00

    单片机c语言万年历设计

    呵呵,这个东西我最近做过。也用过ds1302、pcf8563时钟芯片,还算比较简单啦。只不过没这么多功能,这些日子正想做个跟手表一样多的功能。等做完了,发给你把...

  • 佚名
    2024-06-01 08:00:00

    万年历查询程序. c语言代码

    除了天数差计算,基本上是完成了你所提出的功能(天数差计算其实已经提供了年内序数计算方方法,可以在此基础上完善即可)。包含星期计算、公历转农历、农历转公历、节气查...

  • 佚名
    2024-06-01 08:00:00

    用c语言编程万年历,可以显示时间的,越复杂越好。

    #include<stdio.h>#include<time.h> int leap (int year)//判断闰年 { if(year...

  • 佚名
    2024-06-01 08:00:00

    万年历怎么用c#编写

    w**rm直接放一个datetimepicker1网页的话,网上写一个时间控件

  • 佚名
    2024-06-01 08:00:00

    用c语言编写万年历程序

    // test1.cpp : defines the entry point for the console application.//#include &l...

  • 佚名
    2024-06-01 08:00:00

    求用c语言编写打印万年历的程序代码

    #include<stdio.h>int monthday(int,int);int **leapyear(int);main(){ int d...

  • 佚名
    2024-06-01 08:00:00

    如何用c语言编写一个万年历系统?

    #include <stdio.h>int day,year,month;int **leap(){int **leap;if(((year%4==0)&...