万年历系统——C语言完整版

合集下载

C语言实现万年历程序

C语言实现万年历程序
scanቤተ መጻሕፍቲ ባይዱ("%d",&y); for(i=1;i<y;i++) sum+=year(i);
week=(sum+1)%7; //表示该年1月1日为星期几
if(year(y)==366) days[1]=29;
printf("\n%d年日历如下:\n\n",y);
for(i=0;i<12;i++) { printf(" %d月 \n",i+1); printf(" 7 1 2 3 4 5 6\n"); printf("=====================\n"); begin=1; for(j=0;j<week;j++) printf(" "); while(begin<=days[i]) { printf("%3d",begin); begin++; week=(week+1)%7; if(week%7==0) printf("\n"); } printf("\n\n");
这篇文章主要介绍了visualstudio2000系列版本安装opengl的图文教程本文通过图文并茂的形式给大家介绍的非常详细对大家的学习或工作具有一定的参考借鉴价值需要的朋友可以参考下
C语 言 实 现 万 年 历 程 序
本文实例为大家分享了C语言实现万年历程序,供大家参考,具体内容如下
#include <stdio.h>
}
return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

单片机万年历C语言程序完整

单片机万年历C语言程序完整
sbit out = P2^3; //立刻跳出调整模式按钮
sbit DQ = P3^0;
char done,count,temp,flag,up_flag,down_flag,t_value;
uchar TempBuffer[5],week_value[2];
void show_time(); //液晶显示程序
unsigned char Day;
unsigned char Month;
unsigned char Year;
unsigned char DateString[11];
unsigned char TimeString[9];
}SYSTEMTIME;//定义的时间类型
#define AM(X)X
#define PM(X)(X+12)//转成24小时制
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr|0x01); //地址,命令
ucData = DS1302OutputByte(); //读1Byte数据
DS1302_CLK = 1;
#define DS1302_SECOND0x80 //时钟芯片的寄存器位置,存放时间
#define DS1302_MINUTE0x82
#define DS1302_HOUR0x84
#define DS1302_WEEK0x8A
#define DS1302_DAY0x86
#define DS1302_MONTH0x88
#define uchar unsigned char

c语言万年历程序

c语言万年历程序

#include <stdio.h>#include <stdlib.h>#include <ctype.h>int leap (int year) ;//判断是否为闰年int days_month (int month,int year) ;//判断这个月的天数int menu_select();/*void f(){int day,month,year,sum,leap,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;if(leap==1&&month>2)sum++;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7; //X表示年份,C是该年份元旦开始到这一日的天数//S/7的系数就是星期数//01printf("%d",S);switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}*/int Leap(int year){ int leap;if(year%400==0||(year%4==0&&year%100!=0))leap=1;else leap=0;return leap;}int SU(int sum,int year){int S;S=(year-1+(year-1)/4-(year-1)/100+(year-1)/400+sum)%7;return S;}int Sum(int year,int month,int day=1){int sum,leap;switch(month){case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;}sum=sum+day;leap=Leap(year);if(leap==1&&month>2)sum++;return sum;}void Print(int S){switch(S){case 1:printf("星期一\n");break;case 2:printf("星期二\n");break;case 3:printf("星期三\n");break;case 4:printf("星期四\n");break;case 5:printf("星期五\n");break;case 6:printf("星期六\n");break;case 0:printf("星期日\n");break;}}void Fun1(){int day,month,year,sum,S;printf("\n请输入年月日\n");scanf("%d%d%d",&year,&month,&day);sum=Sum(year,month,day);S=SU(sum,year);Print(S);}void Fun2(){int i,j=1,k=1,a,b,month,year,sum;printf("\n 输入年月:\n");scanf("%d%d",&year,&month);b=days_month(month,year);sum=Sum(year,month);a=SU(sum,year);printf("*************************************\n");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*k-a){printf("\n");k++;}}}printf("\n*************************************\n");printf("\n");}int days_month (int month,int year){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) return 31;if(month==4||month==6||month==9||month==11)return 30;if(month==2&&Leap(year)==1) return 29;else return 28;}void main(){for(;;){switch(menu_select()){case 1:printf("输入年月日计算该月第一天是星期几\n");Fun1();break;case 2:printf("打印任意日历\n");Fun2();break;case 3:printf("谢谢使用!\n");exit(0);}}}int menu_select(){ system("cls");char s;int cn;printf("1. 输入年月日计算该月第一天是星期几\n");printf("2. 打印任意日历\n");printf("3.谢谢使用! \n");printf("input 1-3:");do {s=getchar();cn=(int)s-48;}while(cn<0||cn>6);return cn;}。

C语言-万年历

C语言-万年历

#include"reg51.h"sbit Led1 = P0^0;sbit Led2 = P0^1;sbit Led3 = P0^2;sbit Led4 = P0^3;sbit Led5 = P0^4;sbit SPK = P1^1;sbit Key4 = P1^7;sbit Key2 = P1^5;sbit Key1 = P1^4;void DelayTime(unsigned int DTime){unsigned int uiCnt;for(uiCnt = 0;uiCnt < DTime*50;uiCnt++);}code unsigned char LedSeg[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};main(){unsigned char Second = 59,Minute = 59,Month=29,Day=29,Year=11,Hour=23;unsigned int wCnt = 0;unsigned char BLed = 0,ucLed1 = 1,ucLed2 = 2,ucLed3 = 3,ucLed4 = 4;bit FlashBit = 0; //0: 不闪烁;1:闪烁unsigned char Shift = 0;while(1){/*计时*/if(wCnt > 200){wCnt = 0;if(++Second > 59){ Second = 0;if(++Minute > 59){ Minute = 0;if(++Hour > 23){ Hour = 0;if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Month==12){ if(++Day > 31){ Day = 01 ;if(++Month>12){ Month=01;Year++;}}}else if(Month==2){if(Year%4==0&&Year%100!=0||Year%400==0){if(++Day>29){ Day = 01 ;if(++Month>12){ Month=01;Year++;}}}else{if(++Day>28){ Day = 01 ;if(++Month>12){ Month=01;Year++;}}}}else{if(++Day > 30){ Day = 01 ;if(++Month>12){ Month=01;Year++;}}}}}}}switch(++wCnt % 5){case 0: //显示秒的个位Led2 = 1; //定位显示数码管Led3 = 0;Led4 = 0;Led5 = 0;Led1 = 0;if(FlashBit && Shift == 0){if(wCnt < 100)P2 = LedSeg[ucLed1];//亮elseP2 = 0;//灭}elseP2 = LedSeg[ucLed1];break;case 1:P0 &= 0xe0;Led3 = 1;if(FlashBit && Shift == 1){if(wCnt < 100)P2 = LedSeg[ucLed2];//亮elseP2 = 0;//灭}elseP2 = LedSeg[ucLed2];break;case 2:P0 &= 0xe0;Led4 = 1;if(FlashBit && Shift == 2){if(wCnt < 100)P2 = LedSeg[ucLed3];//亮elseP2 = 0;//灭}elseP2 = LedSeg[ucLed3];break;case 3:P0 &= 0xe0;Led5 = 1;if(FlashBit && Shift == 3){if(wCnt < 100)P2 = LedSeg[ucLed4];//亮elseP2 = 0;//灭}elseP2 = LedSeg[ucLed4];break;case 4:P0 &= 0xe0;Led1 = 1;P2 = LedSeg[BLed];break;}DelayTime(5);if(Key4 == 0){DelayTime(10);while(Key4 == 0);if(!FlashBit){BLed++;if(BLed > 2)BLed = 0;}/*如果切换放置这个位置,会出现什么结果?*/ }if(Key1 == 0){DelayTime(10);while(Key1 == 0);FlashBit = ~FlashBit;}if(Key2 == 0){DelayTime(10);while(Key2 == 0);Shift++;if(Shift > 3)Shift = 0;}switch(BLed){case 0:ucLed1 = Second%10;ucLed2= Second/10;ucLed3= Minute%10;ucLed4= Minute/10;break;case 1:ucLed1 = Hour%10;ucLed2=Hour/10;ucLed3 = Day%10;ucLed4= Day/10;break;case 2:ucLed1 = Month%10;ucLed2 = Month/10;ucLed3 = Year%10;ucLed4= Year/10;break;}} }。

万年历——C语言编写

万年历——C语言编写

万年历的制作,C语言编写!!以下是代码:#include<iostream>#include<cmath>using namespace std;int i,c,day,year,k,a[50];void f1(int x) //大月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000'; //1 号前均为空格for(i=k;i<31+k;i++)a[i]=a[i-1]+1;}void f2(int x) //小月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<30+k;i++)a[i]=a[i-1]+1;}void f3(int x) //闰年二月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<29+k;i++)a[i]=a[i-1]+1;}void f4(int x) //非闰年二月{for( i=0;i<50;i++)a[i]=33;for(i=k-1;i>=0;i--)a[i]='\000';for(i=k;i<28+k;i++)a[i]=a[i-1]+1;}void g(int y[],int z) // 输出日历表{cout<<" 日"<<'\t'<<" 一"<<'\t'<<" 二"<<'\t'<<" 三"<<'\t'<<" 四"<<'\t'<<" 五"<<'\t'<<"六"<<endl;for(i=0;i<50;i++){if(a[i]==0)cout<<(char)a[i]<<'\t';if(a[i]!=0&&a[i]!=33)cout<<a[i]<<'\t';else ;if(i%7==0)cout<<endl;}cout<<endl<<endl<<endl;}int main(){int s,count=0;cout<<"请输入年份:";cin>>year;cout<<endl;c=year;for(s=1;s<=year;s++)if(((s-1)%4==0&&(s-1)%100!=0)||(s-1)%400==0)count++; day=365*c+count; //相差天数cout<<"*********************"<<year<<"年日历*********************";cout<<endl<<endl<<endl<<endl;k=(day%7+6)%7+1;cout<<"一月"<<endl<<endl;f1(k);g(a,50);if((year%4==0&&year%100!=0)||year%400==0){k=((day+31)%7+6)%7+1;cout<<"二月"<<endl<<endl;f3(k);g(a,50);day=day+31+29;}else //非闰年二月{k=((day+31)%7+6)%7+1;cout<<"二月"<<endl<<endl;f4(k);g(a,50);day=day+31+28;}k=(day%7+6)%7+1;cout<<"三月"<<endl<<endl;f1(k);g(a,50);k=((day+31)%7+6)%7+1;cout<<"四月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30)%7+6)%7+1;cout<<"五月"<<endl<<endl;f1(k); g(a,50);k=((day+31+30+31)%7+6)%7+1;cout<<"六月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30+31+30)%7+6)%7+1;cout<<"七月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31)%7+6)%7+1;cout<<"八月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31+31)%7+6)%7+1;cout<<"九月"<<endl<<endl;f2(k);g(a,50);k=((day+31+30+31+30+31+31+30)%7+6)%7+1;cout<<"十月"<<endl<<endl;f1(k);g(a,50);k=((day+31+30+31+30+31+31+30+31)%7+6)%7+1;cout<<"十一月"<<endl<<endl; f2(k);g(a,50);k=((day+31+30+31+30+31+31+30+31+30)%7+6)%7+1;cout<<"十二月"<<endl<<endl;f1(k);g(a,50);return 0;}。

C语言实训--万年历源代码

C语言实训--万年历源代码

C语言实训--万年历源代码# include#include#include#include#include# define YEAR 365int numday[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}};int leap(int year);int calday(int y,int m);int counterdays(int year,int month,int day);int week(int year,int month,int day);int eachyeartotal(int year,int month,int day);int maxDay(int y,int month);void print(int y,int m,int w);void festival (int year,int month,int day);int IsLeap(int y);int guanli(int i);void rili(int year,int month);int rili1();void rili2();void rili3();void rili4();void rili5();void fan();void show(int year,int month,int date,int sec,int mini,int hour);int main(){int i;printf("***************************************\n"); printf("1.查询日历,输入年份:\n");printf("2.查询该月日历及对应星期,输入年份和月份:\n"); printf("3.查询星期几及节日,输入年月日:\n");printf("4.距您输入日期还有多少天,输入日期:\n"); printf("5.通过键盘上下控制不同年月日:\n");scanf("%d",&i);guanli(i);return 0;}int guanli(int i){switch(i){case 1:rili1();return main();case 2:rili2();return main();case 3:rili3();return main();case 4:rili4();return main();case 5:rili5();return main();}return 0;}int rili1(){int year;int n,i;printf("输入年份:");scanf("%d",&year);printf("the calendar of the year%d\n",year);printf("\n");printf("=============================\n"); for(i=1;i<13;i++){printf(" %d月份\n",i);rili(year,i);}n = leap(year);return 0;}void rili2(){int year,month,w;printf("输入年月:");scanf("%d%d",&year,&month);w=calday(year,month);print(year,month,w);}void rili3(){int year,month,day,number;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day);festival(year,month,day);number= week(year,month,day);printf("星期%d",number);}void rili4(){int year,month,day;printf("输入年月日:");scanf("%d%d%d",&year,&month,&day); eachyeartotal( year,month,day);counterdays(year,month,day);}void rili5(){int year,month,date,sec,mini,hour;fan();show(year,month,date,sec,mini,hour);}int leap(int year){int n=(year%4==0 && year%100!=0 || year%100!=0); return n;}void rili(int year,int month){int i,day,first_day,flag,year1,year2;int temp = 6;flag =leap(year);year1=year/100;year2=year%100;if(year>2000){year1=year1-20;day = year1/4;day+=(YEAR+24)*year1+YEAR*year2+(year2-1)/4;if(year>2000)day++;switch(month){case 1:day; break;case 2:day+=31;break;case 3:day+=59+flag;break;case 4:day+=90+flag;break;case 5:day+=120+flag;break;case 6:day+=151+flag;break;case 7:day+=181+flag;break;case 8:day+=212+flag;break;case 9:day+=243+flag;break;case 10:day+=273+flag;break;case 11:day+=304+flag;break;case 12:day+=334+flag;break;}day+=temp;first_day=day%7;}else{year1 = 20-1-year;year2=100-year2-1;day+=(YEAR+24)*year1+YEAR*year2+year2/4; switch(month){case 12:day+=31;break;case 11:day+=61;break;case 10:day+=92;break;case 9:day+=122;break;case 8:day+=153;break;case 7:day+=184;break; case 6:day+=214;break; case 5:day+=245;break; case 4:day+=275;break; case 3:day+=306;break; case 2:day+=334+flag;break; case 1:day+=365+flag;break; }day-=temp;day = day%7;first_day=(7-day)%7;}switch(month){case 1:case 2:month=28+flag;break; case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:month=30;break; case 12:month =31;break;}for(i=1;i<4*first_day;i++) printf(" ");for(i=0;i<month;i++)< p="">{printf("%4d",i+1);if((first_day+i)%7==6)printf("\n");}printf("\n");printf("===============================\n");}///////////////////////////////////////////////////////////int counterdays(int year,int month,int day){int year1,days0,days1,month1,days,day1;time_t timep;struct tm*p;time(&timep);p=gmtime(&timep);year1=(1900+p->tm_year);month1=(1+p->tm_mon);day1=(p->tm_mday);days0=(year-1)*365 + (year-1)/4 - (year-1)/100 + (year-1)/400 +eachyeartotal (year,month,day);days1=(year1 - 1)*365+(year1-1)/4-(year1-1)/100 + (year1 - 1)/400 +eachyeartotal (year1,month1,day1);days=days0-days1;printf("\n今天距%d年%d月%d日还有%d天\n\n",year,month,day,days);return days;}int eachyeartotal(int year,int month,int day){int i,sum=0;for(i=1;i<month;i++)< p="">{sum+=maxDay(year,i);}sum+=day;return sum;}int IsLeap(int y){if(y%4==0 && y%100!=0 || y%400==0) return 1; else return 0;}int maxDay(int y,int month){int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(IsLeap(y))a[1]=29;return a[month-1];}///////////////////////////////////////void festival (int year,int month,int day){if (month==1 && day==1) printf (",这天是元旦");if (month==2 && day==14) printf (",这天是情人节"); if (month == 3)switch(day){case 8:printf (",这天是妇女节"); break;case 12:printf (",这天是植树节");}if (month==1 && day==1) printf (",这天是愚人节");if(month == 5)switch (day){case 1:printf(",这天是劳动节");break;case 4:printf(",这天是青年节");}if (month==6 && day==1) printf (",这天是儿童节");if (month==7 && day==1) printf (",这天是建党节");if (month==8 && day==1) printf (",这天是建军节");if (month==9 && day==10) printf (",这天是教师节");if (month==10 && day==1) printf (",这天是国庆节");printf("\n");}int week(int year,int month,int day){int number = (year-1)+(year-1)/4 - (year-1)/100+(year-1)/400+eachyeartotal(year,month,day);number = number%7;return number;}/////////////////////////////////////////////void print(int y,int m,int w){int i,l;printf("Calendar %d-%02d\n",y,m);printf("---------------------\n");printf("Su Mo Tu We Th Fr Sa \n");printf("---------------------\n");for (i=0;i<w;i++)< p=""> printf(" ");if (IsLeap(y))l=1;elsel=0;for (i=1;i<=numday[l][m-1];i++) {printf("%-3d",i);w++;if (w%7==0)printf("\n");}if (w%7) printf("\n");printf("---------------------\n"); }int calday(int y,int m){int d=0,w;while (y>1910){if (IsLeap(y)) d+=366;else d+=365;y--;}while (m>1){ --m;d+=numday[0][m-1];}w=(d+1)%7;return w;}//////////////////////////////////////////void show(int year,int month,int date,int sec,int mini,int hour) {const char month_str[][4]={"","Jan","Feb","Mar","Apl", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31};int i,j,wdays,mdays,days;for(i=1,days=0;i<year;i++)< p="">{if(leap(i))days += 366;}else{days += 365;}}for(i=1;i<month;i++)< p="">{if(i==2 && leap(year)){days+=29;}else{days+=month_day[i];}}printf(" %s.%d.%d %d:%d:%d \n",month_str[month],date,year,hour,mini,sec);printf(" 一二三四五六日\n");wdays = days % 7;for( j = 0; j < wdays; j++){printf(" ");}if(month == 2 && leap(year)){mdays=29;}else{mdays= month_day[month];}for(i=1;i<=mdays;i++){if( i > 1 && days % 7 == 0 ){printf("\n");}printf("%4d",i);days=days+1; }printf("\n---------------------------\n\n\n");}{time_t rawtime;struct tm *info;int year,month,date,sec,mini,hour; char ch;time ( &rawtime );info = localtime ( &rawtime );year =info->tm_year + 1900; month =info->tm_mon + 1;date =info->tm_mday;hour =info->tm_hour;mini =info->tm_min;sec =info->tm_sec;while(1){show(year,month,date,sec,mini,hour); printf("↑......上一年\n\n");printf("↓......下一年\n\n");printf("←....前一个月\n\n");pr intf("→....后一个月\n\n");printf("Esc.......退出\n\n");ch=getch();switch(ch){case 27://Ecs exit(0);case -32://Navigatorch=getch();if(ch==77){//Rightyear+=(month==12)?1:0;month=month%12+1;}else if(ch==75){year-=(month==1)?1:0; month=(month-2+12)%12+1; }else if(ch==72)year--;else if(ch==80)year++;system("cls");}}</month;i++)<></year;i++)<></w;i++)<></month;i++)<></month;i++)<>。

C语言-万年历

C语言-万年历

#include <stdio.h>#include<time.h> //调用当前时间的头文件#include <stdlib.h>//调用清屏函数的头文件//这是一个万年历的c程序。

void Today(int year,int month,int day)//输出是星期几的函数。

{int d=0,i;int week;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};if(year%4==0&&year%100!=0||year%400==0)//判断是否是闰年。

{for(i=1;i<month;i++)d=d+a[i-1];}else{for(i=1;i<month;i++)d=d+b[i-1];}d=d+day;week=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400+d;//判断这一天是星期几的公式。

week=week%7;//判断这一天是星期几的公式。

当week=0,表示星期日。

//下面是输出星期。

switch(week){case 1:printf("\t%d 年%d 月%d 日是星期: 一",year,month,day);break;case 2:printf("\t%d 年%d 月%d 日是星期: 二",year,month,day);break;case 3:printf("\t%d 年%d 月%d 日是星期: 三",year,month,day);break;case 4:printf("\t%d 年%d 月%d 日是星期: 四",year,month,day);break;case 5:printf("\t%d 年%d 月%d 日是星期: 五",year,month,day);break;case 6:printf("\t%d 年%d 月%d 日是星期: 六",year,month,day);break;case 0:printf("\t%d 年%d 月%d 日是星期: 日",year,month,day);break;}printf("\n\n");}void Tomonth(int year,int month)//输入日历的函数{int week;int t=1;int d=0,i;int a[12]={31,29,31,30,31,30,31,31,30,31,30,31};int b[12]={31,28,31,30,31,30,31,31,30,31,30,31};//这个if和for是计算d的值,d表示到今天为止总共的天数。

1万年历(c语言,多功能)

1万年历(c语言,多功能)

#include "time.h" /*包含的头文件*/#include "stdio.h"#include "math.h"#include "windows.h"#include "conio.h"#define KEYNUMUp 0x48 /*宏定义*/#define KEYNUMDown 0x50#define KEYNUMLeft 0x4b#define KEYNUMRight 0x4dint eachyeartotal(int year,int month,int day>。

/*函数声明*/ int counterdays(int year,int month,int day>。

int nowtime(int year,int month,int day>。

int week(int year,int month,int day>。

int maxDay(int year,int month>。

int isleap(int year>。

void whatweek(int year,int month,int day>。

void display(int year ,int month>。

void display2(int year,int month>。

void display3(int year,int month,int day> 。

void setDay1(int year,int month,int day>。

void setDay2(int year,int month,int day>。

void setDay3(int year,int month,int day>。

void jieri(int month,int day>。

C语言课程设计万年历 完整版

C语言课程设计万年历  完整版

目录一引言 (2)二系统功能和数据说明 (3)一)功能简介 (3)二)程序中的数据说明 (3)三程序总体设计及流程图 (4)一)应用到的c语言 (4)二)程序的总框架 (5)四功能模块设计及调试 (5)一)算法说明 (5)1.总天数的算法 (5)2.计算输入日期是星期几 (6)3.对输入信息的汇总 (8)4..界面的控制 (10)二)调试结果 (11)五程序清单 (12)六结束语 (17)一引言通过大一上学期对C语言的学习,了解到了很多C语言的相关知识。

学习的过程有很多困惑但是当自己能够独立的看懂,能过独立的完成一个简单的程序时,心中就会收获无限的喜悦和成就感。

我可以里哟哦那个它看懂一些简单的程序,编写一些简单的计算程序,更多的是学会了一种思想——编程,它让我在去思考很多日常生活中的事物是怎么样通过一个个小小的函数实现功能的,激发我对探究的兴趣。

C语言是近年在国内外得到迅速推广应用的一种语言。

C语言功能丰富,表达能力强,使用灵活方便,应用面广,目标程序效率高,可移植性好,既具有高级语言的优点,又具有低级语言的许多特点。

因此,C语言特别适合于编写各种软件。

在这次的课程设计中我将把日常生活中最经常接触的——日期的查询利用C语言的程序编成一个简单的日历。

通过这个小小的日历可以实现很多功能。

在程序中你能看到很多熟悉的C语言关键字,同时也加入了很多自己课外了解到的一些关键字。

在不断的调试中最终才获得最为完整的程序。

接下来就是我的C 语言课程设计的具体内容来了二系统功能和数据说明(一)功能简介在我们的日常生活中能接触到很多不同类型的日历,在日历上我们通常希望它能简介明了的给我们最想要的日期信息。

在我的万年历当中,就是将日历,月历做的简单明了,很方便我们的使用。

下面是它要实现的一些基本功能:用C语言编写万年历1、输入年份,判断是否为闰年2、输入年月日,判断改日为星期几3、输入年份,打出12个月历,输入月份,打出该月的日历4、要求用多个函数实现[名称]万年历[修改]1、对输入的日期进行容错处理2、增加和修改为英文的月份和星期显示3、采用指针形式的weeks和month数组(二)程序中的数据说明①int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};这是定义的关于每个月天数的数组,根据大小月以及二月分的特殊情况将每个月的天数最为数组中的元素存入数组当中。

(完整版)C语言万年历

(完整版)C语言万年历
C
说明部分
在TC或VC6.0中编译程序,编译成功后,通过命令行向编译生成的可执行文件(.exe)传递参数,在命令行中输入该执行文件的路径名称,然后再输入传入的参数,回车,就会显示出运行结果,效果如图1.1所示。
图1.1万年历运行界面
代码部分
#include <stdio.h>
main(int a,char **date)
}
if (day<0||day>month)
{
printf ("\n ERROR! the entered DAY is invalid\n");
exit (0);
}
week=(dy+dm+day-1+6)%7;
if(week<0)
week+=7;
if (day>0) /***判定查看类型***/
{
if (d==-1) year=year*10+(date[1][i]-'0');
if (d==0) month=month*10+(date[1][i]-'0');
if (d==1) day=day*10+(date[1][i]-'0');
i++;
}
if (month<1||month>12)/*若月份传入错误数字*/
else
d=(year-2000)/4-(year-2000)/100+(year-2000)/400;
dy=(year-2000)+d; /***该年1月1号到2000年1月1号的"星期差" ***/

用C语言写的万年历

用C语言写的万年历
ACC = ACC >> 1;
}
}
unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数)
{
unsigned char i;
for(i=8; i>0; i--)
{
ACC = ACC >>1; //相当于汇编中的 RRC
DS1302_CLK = 1;
DS1302_RST = 0;
}
unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据
{
unsigned char ucData;
DS1302_RST = 0;
{
unsigned char i;
ACC = d;
for(i=8; i>0; i--)
{
DS1302_IO = ACC0; //相当于汇编中的 RRC
DS1302_CLK = 1;
DS1302_CLK = 0; //上升沿沿写入数据
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
{ if(hide_year<2) //这里的if,else语句都是判断位闪烁,<2显示数据,>2就不显示,输出字符串为 2007/07/22

51单片机c语言电子万年历完整程序

51单片机c语言电子万年历完整程序

该程序为51单片机c语言电子万年历#include"reg52.h"//#include<stdio.h>#define uchar unsigned char#define uint unsigned intsbit lcden=P3^4;sbit lcdrs=P3^5;sbit DATA=P0^7;sbit RST=P0^5;sbit SCLK=P0^6;sbit menu=P3^0; //菜单sbit add=P3^1; //加一sbit dec=P3^7; //减一sbit led0=P1^0;sbit led1=P1^1;sbit led2=P1^2;sbit led3=P1^3;sbit ds=P3^2;//sbit beep=P3^3;uint temp;float f_temp;uint warn_l1=270;uint warn_l2=250;uint warn_h1=300;uint warn_h2=320;uint get_temp();void delayms(uint x);void write_com(uchar com);void write_data(uchar date);void init();void dis_temp(uint t);void Write1302(uchar dat);void WriteSet1302(uchar Cmd,uchar dat);uchar Read1302(void);uchar ReadSet1302(uchar Cmd);void Init_DS1302(void);void DisplaySecond(uchar x);void DisplayMinute(uchar x);void DisplayHour(uchar x);void DisplayDay(uchar x);void DisplayMonth(uchar x);void DisplayYear(uchar x);void DisplayWeek(uchar x);void dis_temp(uint t);void read_date(void);void turn_val(char newval,uchar flag,uchar newaddr,uchar s1num);void key_scan(void);char code table[]="0123456789" ;uchar code table2[]= "TUEWESTHUFRISATSUNMON"; uchar second,minute,hour,day,month,year,week,count=0; uchar ReadValue,num,time;void delayms(uint x){uint i,j;for(i=x;i>0;i--)for(j=110;j>0;j--);}////////////////////////////////////////////////////////////void write_com(uchar com){lcdrs=0;P2=com;delayms(5);lcden=1;delayms(5);lcden=0;}void write_data(uchar date){lcdrs=1;P2=date;delayms(5);lcden=1;delayms(5);lcden=0;}void init(){lcden=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);}/////////////////////////////////////////////////////////////////void Write1302(uchar dat){uchar i;SCLK=0; //拉低SCLK,为脉冲上升沿写入数据做好准备 delayms(2); //稍微等待,使硬件做好准备for(i=0;i<8;i++) //连续写8个二进制位数据DATA=dat&0x01; //取出dat的第0位数据写入1302delayms(2); //稍微等待,使硬件做好准备SCLK=1; //上升沿写入数据delayms(2); //稍微等待,使硬件做好准备SCLK=0; //重新拉低SCLK,形成脉冲dat>>=1; //将dat的各数据位右移1位,准备写入下一个数据位 }}void WriteSet1302(uchar Cmd,uchar dat){RST=0; //禁止数据传递SCLK=0; //确保写数居前SCLK被拉低RST=1; //启动数据传输delayms(2); //稍微等待,使硬件做好准备Write1302(Cmd); //写入命令字Write1302(dat); //写数据SCLK=1; //将时钟电平置于已知状态RST=0; //禁止数据传递}uchar Read1302(void){uchar i,dat;delayms(2); //稍微等待,使硬件做好准备for(i=0;i<8;i++) //连续读8个二进制位数据dat>>=1; //将dat的各数据位右移1位,因为先读出的是字节的最低位if(DATA==1) //如果读出的数据是1dat|=0x80; //将1取出,写在dat的最高位SCLK=1; //将SCLK置于高电平,为下降沿读出delayms(2); //稍微等待SCLK=0; //拉低SCLK,形成脉冲下降沿delayms(2); //稍微等待}return dat; //将读出的数据返回}uchar ReadSet1302(uchar Cmd){uchar dat;RST=0; //拉低RSTSCLK=0; //确保写数居前SCLK被拉低RST=1; //启动数据传输Write1302(Cmd); //写入命令字dat=Read1302(); //读出数据SCLK=1; //将时钟电平置于已知状态RST=0; //禁止数据传递return dat; //将读出的数据返回}void Init_DS1302(void){WriteSet1302(0x8E,0x00); //根据写状态寄存器命令字,写入不保护指令WriteSet1302(0x80,((0/10)<<4|(0%10))); //根据写秒寄存器命令字,写入秒的初始值WriteSet1302(0x82,((59/10)<<4|(59%10))); //根据写分寄存器命令字,写入分的初始值WriteSet1302(0x84,((23/10)<<4|(23%10))); //根据写小时寄存器命令字,写入小时的初始值WriteSet1302(0x86,((28/10)<<4|(28%10))); //根据写日寄存器命令字,写入日的初始值 WriteSet1302(0x88,((2/10)<<4|(2%10))); //根据写月寄存器命令字,写入月的初始值WriteSet1302(0x8c,((14/10)<<4|(14%10))); //nian//WriteSet1302(0x8a,((4/10)<<4|(4%10)));}/////////////////////////////////////////////////////////////////void DisplaySecond(uchar x){uchar i,j;i=x/10;j=x%10;write_com(0x80+0x46);write_data(i+0x30);write_com(0x80+0x47);write_data(j+0x30);write_com(0x80+0x48);write_data(' ');dis_temp(get_temp());}void DisSecond(uchar x){uchar i,j;ReadValue = ReadSet1302(0x81);second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);i=x/10;j=x%10;write_com(0x80+0x46);write_data(i+0x30);write_com(0x80+0x47);write_data(j+0x30);}void DisplayMinute(uchar x) {uchar i,j;i=x/10;j=x%10;write_com(0x80+0x43);write_data(i+0x30);write_com(0x80+0x44);write_data(j+0x30);write_com(0x80+0x45);write_data(':');}void DisplayHour(uchar x){uchar i,j;i=x/10;j=x%10;write_com(0x80+0x40);write_data(i+0x30);write_com(0x80+0x41);write_data(j+0x30);write_com(0x80+0x42);write_data(':');}void DisplayDay(uchar x) {uchar i,j;i=x/10;j=x%10;write_com(0x89);write_data(i+0x30);write_com(0x8a);write_data(j+0x30); }void DisplayMonth(uchar x) {uchar i,j;i=x/10;j=x%10;write_com(0x86);write_data(i+0x30); write_com(0x87);write_data(j+0x30);write_com(0x88);write_data('/');}void DisplayYear(uchar x) {uchar i,j;i=x/10;j=x%10;write_com(0x81);write_data(2+0x30);write_com(0x82);write_data(0+0x30);write_com(0x83);write_data(i+0x30);write_com(0x84);write_data(j+0x30);write_com(0x85);write_data('/');}void DisplayWeek(uchar x){ uchar i;x=x*3;// write_com(0x8c);write_data(table2[x]);// write_com(0x8d);write_data(table2[x+1]);// write_com(0x8e);write_data(table2[x+2]);write_com(0x8c);for(i=0;i<3;i++){write_data(table2[x]);x++;}}void read_date(void){ReadValue = ReadSet1302(0x81);second=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = ReadSet1302(0x83);minute=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = ReadSet1302(0x85);hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = ReadSet1302(0x87);day=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = ReadSet1302(0x89);month=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = ReadSet1302(0x8d);year=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue=ReadSet1302(0x8b); //读星期week=ReadValue&0x07;DisplayYear(year);DisplayMonth(month);DisplayDay(day);DisplayWeek(week);DisplayHour(hour);DisplayMinute(minute);DisplaySecond(second);dis_temp(get_temp()); ///温度显示key_scan(); ///按键检测}void turn_val(char newval,uchar flag,uchar newaddr,uchar s1num){newval=ReadSet1302(newaddr); //读取当前时间newval=((newval&0x70)>>4)*10+(newval&0x0f); //将bcd码转换成十进制 if(flag) //判断是加一还是减一{newval++;switch(s1num){ case 1: if(newval>99) newval=0;DisplayYear(newval);break;case 2: if(newval>12) newval=1;DisplayMonth(newval);break;case 3: if(newval>31) newval=1;DisplayDay(newval);break;case 4: if(newval>6) newval=0;DisplayWeek(newval);break;case 5: if(newval>23) newval=0;DisplayHour(newval);break;case 6: if(newval>59) newval=0;DisplayMinute(newval);break;case 7: if(newval>59) newval=0;DisplaySecond(newval);break;default:break;}}else{newval--;switch(s1num){ case 1: if(newval==0) newval=99;DisplayYear(newval);break;case 2: if(newval==0) newval=12;DisplayMonth(newval);break;case 3: if(newval==0) newval=31;DisplayDay(newval);break;case 4: if(newval<0) newval=6;DisplayWeek(newval);break;case 5: if(newval<0) newval=23;DisplayHour(newval);break;case 6: if(newval<0) newval=59;DisplayMinute(newval);break;case 7: if(newval<0) newval=59;DisplaySecond(newval);break;default:break;}}WriteSet1302((newaddr-1),((newval/10)<<4)|(newval%10)); //将新数据写入寄存器}//////////////////////////////////////void dsreset(void){uint i;ds=0;i=103;while(i>0)i=4;while(i>0)i--;}bit tempreadbit(void){uint i;bit dat;ds=0;i++;ds=1;i++;i++;dat=ds;i=8;while(i>0)i--;return(dat);}uchar tempread(void){uchar i,j,dat;dat=0;for(i=1;i<=8;i++){j=tempreadbit();dat=(j<<7)|(dat>>1); }return(dat);}void tempwritebyte(uchar dat) {bit testb;for(j=1;j<=8;j++){testb=dat&0x01;dat=dat>>1;if(testb){ds=0;i++;i++;ds=1;i=8;while(i>0)i--;}else{ds=0;i=8;while(i>0)i--;ds=1;i++;i++;}}}void tempchange(void) {dsreset();delayms(1);tempwritebyte(0xcc);tempwritebyte(0x44);key_scan(); //////按键函数}uint get_temp(){uchar a,b;tempchange(); //////温度函数dsreset();delayms(1);tempwritebyte(0xcc);tempwritebyte(0xbe);a=tempread();b=tempread();temp=b;temp<<=8;temp=temp|a;f_temp=temp*0.0625;temp=f_temp*10+0.5;f_temp=f_temp+0.05;return temp;}//////void dis_temp(uint t){uchar n1,n2,n3;n1=t/100;n2=t%100/10;n3=t%100%10;DisSecond(second); ///秒显示 write_com(0x80+0x49);write_data(table[n1]);//delayms(5);write_com(0x80+0x4a);write_data(table[n2]);//delayms(5);write_com(0x80+0x4b);write_data('.');// delayms(5);write_com(0x80+0x4c);write_data(table[n3]);//delayms(5);write_com(0x80+0x4d);write_data('^');//delayms(5);write_com(0x80+0x4e);write_data('C');//delayms(5);DisSecond(second); ////秒显示}/*********************液晶显示*****************/ void warn(uint s,uchar led){uchar i;i=s;// beep=0;P1=~(led);while(i--){dis_temp(get_temp());}// beep=1;P1=0xff;i=s;while(i--){dis_temp(get_temp());}}void deal(uint t){uchar i;if((t>warn_l2)&&(t<=warn_l1)){warn(40,0x01);}else if(t<=warn_l2){warn(10,0x03);}else if((t<warn_h2)&&(t>=warn_h1)) {warn(40,0x04);}else if(t>=warn_h2){warn(10,0x0c);}else{i=40;while(i--){dis_temp(get_temp());DisSecond(second);}}}///////////////////////////////////////void main(){init();Init_DS1302();while(1){tempchange();read_date();deal(temp);key_scan();}}////******************************************* void key_scan(void){// uchar miao,s1num=0;uchar s1num=0;if(menu==0){delayms(5);if(menu==0){while(!menu);s1num++;while(1){if(menu==0){delayms(5);if(menu==0){while(!menu);s1num++;}}// miao=ReadSet1302(0x81);// second=miao;// WriteSet1302(0x80,miao|0x80);write_com(0x0f);//光标闪射if(s1num==1){ //year=ReadSet1302(0x8d);write_com(0x80+4); //年光标if(add==0){delayms(3);if(add==0){ while(!add);turn_val(year,1,0x8d,1);}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(year,0,0x8d,1);}}}if(s1num==2){//month=ReadSet1302(0x89);write_com(0x80+7); //月光标if(add==0){delayms(3);if(add==0){ while(!add);turn_val(month,1,0x89,2);}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(month,0,0x89,2);}}}if(s1num==3){ //day=ReadSet1302(0x87);write_com(0x80+10);//日光标{delayms(3);if(add==0){ while(!add);turn_val(day,1,0x87,3);}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(day,0,0x87,3); //写入日寄存器 }}}if(s1num==4){ //week=ReadSet1302(0x8b);write_com(0x80+14); //星期光标if(add==0){delayms(3);if(add==0){ while(!add);turn_val(week,1,0x8b,4);}}if(dec==0){delayms(3);{ while(!dec);turn_val(week,0,0x8b,4);}}}if(s1num==5){// hour=ReadSet1302(0x85)write_com(0x80+0x40+1); //时光标if(add==0){delayms(3);if(add==0){ while(!add);turn_val(hour,1,0x85,5);}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(hour,0,0x85,5);}}}if(s1num==6)//调时间分{ // minute=ReadSet1302(0x83);write_com(0x80+0x40+4);if(add==0){delayms(5);if(add==0){ while(!add);turn_val(minute,1,0x83,6); //写入分寄存器}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(minute,0,0x83,6); //写入分寄存器}}}if(s1num==7)//调时间秒{// second=ReadSet1302(0x81);write_com(0x80+0x40+7);//秒光标if(add==0){delayms(3);if(add==0){ while(!add);if(second==0x60)second=0x00;turn_val(second,1,0x81,7);}}if(dec==0){delayms(3);if(dec==0){ while(!dec);turn_val(second,0,0x81,7);}}}if(s1num==8){// miao=ReadSet1302(0x81);// second=miao;// WriteSet1302(0x80,second&0x7f);s1num=0;//s1num清零//write_com(0x0c);//光标不闪烁//break;}}}}}。

万年历c语言程序

万年历c语言程序

万年历-c语言程序#include; sbit p1_0=P1^0; sbit p1_1=P1^1; sbitp1_2=P1^2; sbit p1_3=P1^3; sbit p1_4=P1^4; sbit p3_2=P3^2; unsigned char code zimal[13]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6 F,0x40,0x80,0x00,}; /*共阴极字形代码,显示0-9字形码,最后三个代码分别表示&lsquo;-&rsquo;,&lsquo;.&rsquo;&lsquo;熄灭&rsquo;*/ unsigned int year,month,day,hour,minute,second;//定义变量年,月,日,时,分,秒; void delay();//延时函数; void xianshi(unsigned int h,min,s);//显示时间函数; voidymdxianshi(unsigned int year,month,day);//显示年月日; void fengming();//蜂鸣器函数; int leap(unsigned int year);//判断闰年函数; unsigned int h,m,s=5;//记录定时时间; unsigned int mode=1,td=0,yw=0;//状态; voidmain(){ year=2010;month=5;day=20;hour=23;minute=59;second=0; /*初始化年,月,日,时,分,秒*/TMOD=0x10;//定时器1;模式1; TL1=0xb0;TH1=0x3c;定时时间为50msTR1=1;//打开定时器1ET1=1;//定时器1溢出中断允许位EX0=1;//外部中断0允许IT0=1;//外部中断0触发方式为边沿触发EA=1; while(1) //主循环;{if(hour==h&&minute==m&&second==s) fengming(); //定时时间到,蜂鸣器响;if(mode%2==0) ymdxianshi(year,month,day); //显示年月日 else{if(td%3==2)xianshi(h,m,s); // 定时状态;elsexianshi(hour,minute,second); //正常显示时间状态;}}void delay()//延时函数;{ unsigned int i; for(i=0;i;=2500)year=0; //年份小于2500;if(month>;12)month=1;//月份小于12;switch(month)//日期限制{case 4:case 6:case 9:case 11:if(day>;30)day=1;break;//4,6,9,11月30天;case 2 :(leap(year))//闰年2月29天;while(day>;29)day=1;elsewhile(day>;28)day=1;//非闰年28天;}break; default:if(day>;31)day=1; //1,3,5,7,8,10,12月31天;}}}//else if(td%3==1) //调整时间; else if(td%3==1) { ET1=0; //时钟中断 for(i=0;i;23)hour=0;if(minute>;59)minute=0; if(second>;59)second=0;} else//定时状态;ET1=1;if(td%3==2){for(i=0;i;23)h=0;if(m>;59)m=0;if(s>;59)s=0;}}} voidtime1()interrupt 3 //定时器1中断; { unsigned char i;TF0=0; TL0=0xb0; TH0=0x3c; i++;if(i==20) //1秒钟到;second++;i=0;}if(second==60)//1分钟;{second=0;minute++;}if(minute==60)//1小时; {minute=0; hour++; } if(hour==24) //1天;{hour=0;day++;}switch(month) //1 月;case 4:case 6:case 9:case11:if(day>;30){month++;day=1;}break;//4,6,9,11月30天;case 2:{if(leap(year))if(day>;29){month++;day=1;} //闰年29天; elseif(day>;28){month++;day=1;}//非半闰年28天;}break;default:if(day>;31){month++;day=1;}//1,3,5,7,8,10 ,12月30天;if(month>;12) //1年;{year++;month=1;}} } void fengming() //蜂鸣器; { int m,n; for (m=0;m<=100;m++) {p1_4=!p1_4;for(n=0;n<380;n++); } }int leap(unsigned int year) //判断闰年函数; { int leap; if(year%4==0&&year%100!=0||(year%400==0)) leap=1; else leap=0;return(leap); }。

C语言编写万年历

C语言编写万年历

C语言编写万年历【要求】:1.程序运行后,首先在屏幕上显示主菜单:2.查询某年某月某日是星期几3.查询某年是否是闰年4.打印某年的全年日历5.退出2.在主菜单中输入1后,显示:“请输入年月日(XXXX,XX,XX)”运行后输出:XXXX年XX月XX日是星期X,是否继续查询(Y/N)?如果输入Y,则重新显示“请输入年月日(XXXX,XX,XX)”,否则回到主菜单。

3.在主菜单中输入2后,显示:“请输入要查哪一年?(XXXX)”运行后输出:XXXX年是(否)是闰年,是否继续查询(Y/N)?如果输入Y,则重新显示,“请输入要查哪一年?(XXXX)”,否则回到主菜单。

4.在主菜单中输入3后,显示:“请输入要打印的年份(XXXX)”运行后输出XXXX年的日历,格式为:XXXXX(月数.奇) X(月数.)0 1 2 3 4 5 6 0 1 2 3 4 5 6 S M T W T F S S M T W T F S x x x x x x x x x x xx x x xx xx xx xx x x x xx xx xx xx xx xx xx xx xx xx xx x x x xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 运行完后显示:“是否继续打印(Y/N)?”如果输入Y,则重新显示,“请输入要打印的年份(XXXX)”,否则回到主菜单。

5.在主菜单中输入4后,显示:“是否要真的退出(Y/N)?”如果输入Y,结束程序运行,否则重新显示主菜单。

代码来自东篱下,Turbo C&C++3.0编译调试通过,已经验证输出结果正确:#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"void menu(){system("cls");printf("\nTHIS IS THE MENU OF THE PROGRAM !");printf("\nYOU CAN CHOOSE THE NUMBER FOR THE FUNCTIOM:"); printf("\n\n");printf("1 Find the day by year-month-date.\n");printf("2 Find the year you input if the leap year.\n");printf("3 Print the calendar of the year you input.\n");printf("4 Exit.\n\n");printf("Input your choice:");}/*函数定义,将在主函数中调用*/int getday(int year,int month,int date){int flag,s,i;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};int cont=0;flag=isleap(year);if(flag==1)/*修改二月份天数*/a[2]++;for(i=1;i<month;i++){cont=cont+a[i];}cont=cont+date;s=year+1+(year-1)/4+(year-1)/100+(year-1)/400+cont; return s%7;/*利用公式求星期几*/}int isleap(int year){if(year%4==0&&year%100||year%400==0)return 1;elsereturn 0;}/*判定闰年*/void print(int n){int i;for(i=0;i<n;i++) printf(" ");}/*打印空格,排版使用*/int day(int year){int a,b;if(year<=2000){a=2000-year;b=6-(a+a/4-a/100+a/400)%7;return b;}else{a=year-2000;b=(a+1+(a-1)/4-(a-1)/100+(a-1)/400)%7+6;return b%7;}}/*打印日历函数*/void printcalendar(int year){int i,j,k,m,n,f1,f2,d;int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};printf("\nThe calendar of the year %d.\n\n",year);d=day(year);if(isleap(year)==1)a[2]++;for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:printf(" Januray 1 ");break;case 3:printf(" March 3 ");break;case 5:printf(" May 5 ");break;case 7:printf(" July 7 "); break;case 9:printf(" September 9 ");break;case 11:printf(" Nevember 11 ");break;}print(21); /*打印空格,隔开奇偶月份名*/switch(i+1){case 2:printf(" February 2 "); break;case 4:printf(" April 4 "); break;case 6:printf(" June 6 "); break;case 8:printf(" August 8 "); break;case 10:printf(" October 10 "); break;case 12:printf(" December 12"); break;}printf("\n");printf(X); /*宏调用,打印星期字符串*/print(6);/*打印空格,隔开奇偶月份数据*/printf(X);printf("\n");for(j=0;j<6;j++){if(j==0){print(d*4); /*每个日期数采用个空格的宽度,即4字节。

C语言编写方案 万年历

C语言编写方案 万年历

结束 图 6-2 系统流程图
第 3 页 共 22 页
《C 语言程序设计》课程综合案例
}Lunar_ipedef struct {
int era_year; //阳历年份 int era_month; //阳历月份 int era_day; //阳历日期 }Chinese_era;
int get_lunar_info(int solar_year, int solar_month, Lunar_info *l_info,Chinese_era *china_era):返回农历信
息;
第 2 页 共 22 页
《C 语言程序设计》课程综合案例
int out_chinese(Lunar_info *l_info,char *chinese_str):输出农历日期信息; void sub_menue():界面输出。
"小寒","大寒","立春","雨水","惊蛰","春分", "清明","谷雨","立夏","小满","芒种","夏至", "小暑","大暑","立秋","处暑","白露","秋分", "寒露","霜降","立冬","小雪","大雪","冬至" }; /*农历日*/ char chinese_day[30][5]= { "初一","初二","初三","初四","初五","初六","初七",
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验十九:编写一个万年历系统
1.设计目的:
从实验的角度来看,这次课程设计一方面可以让自己巩固并加深对C语言程序设计知识的理解,掌握和提高C语言编程和程序的基本调试的基本技能,进一步理解和运用结构化程序的思想和方法;另一方面,可以让自己在面对一个全新的问题时,学会如何思考,如何寻找问题的关键,从而提升自己的能力。

2.总体设计:
1.、当前页以系统当前日期的月份为准,显示当前月的每一天(显示出日及对应的星期几);
2、当系统日期变到下一个月时,系统自动翻页到下一月。

3.调试与测试:
4.源程序清单和执行结果:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
int leap(int year )
{
if ((year %4 == 0) && (year % 100 != 0)
|| (year % 400 == 0))
{
return 1;
}
return 0;
}
void show(int year,int month,int date,int sec,int mini,int hour) {
const char month_str[][4]={"","Jan","Feb","Mar","Apl", "May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
const int month_day[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int i,j,wdays,mdays,days;
for(i=1,days=0;i<year;i++)
{
if(leap(i))
{
days += 366;
}
else
{
days += 365;
}
}
for(i=1;i<month;i++)
{
if(i==2 && leap(year))
{
days+=29;
}
else
{
days+=month_day[i];
}
}
printf(" %s.%d.%d %d:%d:%d \n",month_str[month],date,year,hour,mini,sec);
printf(" 一二三四五六日\n");
wdays = days % 7;
for( j = 0; j < wdays; j++)
{
printf(" ");
}
if(month == 2 && leap(year))
{
mdays=29;
}
else
{
mdays= month_day[month];
}
for(i=1;i<=mdays;i++)
{
if( i > 1 && days % 7 == 0 )
{
Printf(“\n”);
printf("\n");
}
printf("%4d",i);
days=days+1;
}
printf("\n---------------------------\n\n\n");
}
void main()
{
time_t rawtime;
struct tm *info;
int year,month,date,sec,mini,hour; char ch;
time ( &rawtime );
info = localtime ( &rawtime );
year =info->tm_year + 1900; month =info->tm_mon + 1;
date =info->tm_mday;
hour =info->tm_hour;
mini =info->tm_min;
sec =info->tm_sec;
while(1)
{
show(year,month,date,sec,mini,hour); printf("↑......上一年\n\n");
printf("↓......下一年\n\n");
printf("←....前一个月\n\n");
printf("→....后一个月\n\n");
printf("Esc.......退出\n\n");
ch=getch();
switch(ch)
{
case 27://Ecs
exit(0);
case -32://Navigator
ch=getch();
if(ch==77)
{//Right
year+=(month==12)?1:0;
month=month%12+1;
}
else if(ch==75)
{//Left
year-=(month==1)?1:0;
month=(month-2+12)%12+1;
}
else if(ch==72) {//Up
year--;
}
else if(ch==80) {//Down
year++;
}
system("cls"); }
}
}。

相关文档
最新文档