C语言万年历(源代码)

合集下载

万年历c语言源程序

万年历c语言源程序

万年历c语言源程序#include stdio.h #include windows.h #include wincon.h #includestring.h #includestdlib.h #includeconio.h #includetime.h #includemath.h #define NULL 0*****_SCREEN_BUFFER_INFO csbiInfo; extern *****API HWND WINAPI GetConsoleWindow(); time_t T;struct tm * now; int min,sec;int hour,nowyear,nowmonth,nowday; void ti2() { time ( T ); now = localtime ( T ); hour=now-tm_hour%12; min=now-tm_min-15; sec=now-tm_sec-15; }void ti(){ time ( T ); now = localtime ( T ); hour=now-tm_hour; min=now-tm_min; sec=now-tm_sec; nowyear=now-tm_year+1900; nowmonth=now-tm_mon+1; nowday=now-tm_mday; }int yearbak=0; void clock_sz(); int pd( int year);void huizs(int line_head_month); void hzdy(int year,int nowmonth_hz); void menu(); void clear();int main(int argc, char* argv[]) { int x=0; ti();clock_sz(); hzdy(nowyear,nowmonth); menu(); return 0; }void clear() { int i; HWND hwnd; HANDLE hOut; HDC hdc;HBRUSH hbr; COORD pos={1,4}; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd); hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,0,0)); SelectObject(hdc,hbr); Rectangle(hdc,0,65,670,470); SetConsoleCursorPosition(hOut, pos); for(i=0;i i++) printf(“ \n "); SetConsoleCursorPosition(hOut, pos); Rectangle(hdc,0,65,670,470); ReleaseDC(hwnd, hdc); } void menu() { int year=0,xyear=0,x, xy=0,i ; struct re { int top; int left; int right; int bottom; }rt; HWND hwnd; HDC hdc,dc; HBRUSH hbr; COORD pos3_1 = {1, 4},pos3_2= {1, 1},pos = {1, 4},pos2_3 = {1, 6},pos2_4 = {1, 7}; INPUT_RECORD mouseRec; DWORD state = 0, res=0; POINT pt; HPEN pn;HANDLE hOut, hIn;hwnd=GetConsoleWindow();//得到控制台窗口句柄hdc = GetDC(hwnd); //得到画图设备句柄dc = GetDC(hwnd);//画刷hbr= CreateSolidBrush(RGB(255,0,0)); SelectObject(dc,hbr);for(rt.left=20,i=2;ii++) rt[i].left=rt[i-1].left+50;for(rt.right=50,i=2;ii++) rt[i].right=rt[i-1].right+50; //定位按钮for(i=0;ii++) rt[i].top=40; for(i=0;ii++) rt[i].bottom=60;hOut = GetStdHandle(STD_OUTPUT_HANDLE); hIn=GetStdHandle(STD_INPUT_HANDLE);pn=CreatePen(PS_SOLID,1,RGB(255,0,255)); GetClientRect(hwnd, rt); SelectObject(hdc, pn);SetBkMode(hdc,*****RENT); MoveToEx(hdc,1,35,NULL); LineTo(hdc,620,35); LineTo(hdc,620,62); LineTo(hdc,1,62); LineTo(hdc,1,35);pn=CreatePen(PS_SOLID,2,RGB(255,255,0));SelectObject(hdc, pn);MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75);hbr= CreateSolidBrush(RGB(0,0,190)); SelectObject(dc,hbr); for(i=1;ii++) Rectangle(dc,rt[i].left,rt[i].top,rt[i].right,rt[i].bottom);SetTextColor(hdc,RGB(0,255,255));TextOut(hdc,280,10,TEXT("万年历"),6);//输出文本SetTextColor(hdc,RGB(255,255,0));////设颜色TextOut(hdc,rt.left,rt.top,TEXT(" 1"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 2"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 3"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 4"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 5"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 6"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 7"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 8"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 9"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT(" 0"),3);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT("确定"),4);//输出文本TextOut(hdc,rt.left+=50,rt.top,TEXT("清除"),4);//输出文本TextOut(hdc,40,350,TEXT("提示:双击窗口退出"),18);//输出文本SetConsoleCursorPosition(hOut, pos3_1); ShowWindow(hwnd,SW_SHOW); SetConsoleTextAttribute(hOut, 10); for(;;) { SetConsoleTextAttribute(hOut, 10); ReadConsoleInput(hIn, mouseRec, 1, res); Sleep(100); if (mouseRec.EventType == MOUSE_EVENT) { if (mouseRec.Event.MouseEvent.dwEventFlags == DOUBLE_CLICK) break; if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_*****) { GetCursorPos(pt); ScreenToClient(hwnd,pt); if(pt.x20 pt.x50 pt.yrt.top pt.yrt.bottom) { if(xyear4) printf("1"); xyear++; if(xyear==1) year=1*1000; if(xyear==2) year=year+1*100; if(xyear==3) year=year+1*10; if(xyear==4) { year=year+1; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.top pt.yrt.bottom) { if(xyear4) printf("2"); xyear++; if(xyear==1) year=2*1000; if(xyear==2) year=year+2*100;if(xyear==3) year=year+2*10; if(xyear==4){ year=year+2;printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom) { if(xyear4) printf("3"); xyear++; if(xyear==1) year=3*1000; if(xyear==2) year=year+3*100; if(xyear==3) year=year+3*10; if(xyear==4){ year=year+3; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("4"); xyear++; if(xyear==1) year=4*1000; if(xyear==2) year=year+4*100; if(xyear==3) year=year+4*10; if(xyear==4){ year=year+4; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("5"); xyear++; if(xyear==1) year=5*1000; if(xyear==2) year=year+5*100; if(xyear==3) year=year+5*10; if(xyear==4){ year=year+5;pt.yrt.top pt.yrt.top pt.yrt.topprintf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("6"); xyear++; if(xyear==1) year=6*1000; if(xyear==2) year=year+6*100; if(xyear==3) year=year+6*10; if(xyear==4){ year=year+6; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("7"); xyear++; if(xyear==1) year=7*1000; if(xyear==2) year=year+7*100; if(xyear==3) year=year+7*10;if(xyear==4){ year=year+7; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("8"); xyear++; if(xyear==1) year=8*1000; if(xyear==2) year=year+8*100; if(xyear==3) year=year+8*10; if(xyear==4){ year=year+8; printf("\n你选择的年为%d",year);pt.yrt.top pt.yrt.top pt.yrt.top} continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("9"); xyear++; if(xyear==1) year=9*1000; if(xyear==2) year=year+9*100; if(xyear==3) year=year+9*10; if(xyear==4){ year=year+9; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear4) printf("0"); xyear++; if(xyear==1) year=0*1000; if(xyear==2) year=year+0*100; if(xyear==3) year=year+0*10; if(xyear==4){ year=year+0; printf("\n你选择的年为%d",year); } continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.bottom){ if(xyear=1year!=0) { clear(); yearbak=year; SetConsoleCursorPosition(hOut, pos3_2); printf("公元%d年",yearbak); SetConsoleCursorPosition(hOut, pos3_1); for(i=1;ii+=3) huizs(i);pt.yrt.top pt.yrt.top pt.yrt.topx=MessageBox(NULL,"是否显示后六个月?", "提示",MB_YESNO); if(x==6) { SetConsoleTextAttribute(hOut, 14); clear(); for(i=7;ii+=3) huizs(i); } } else printf("输入不合法,请点击清除重新输入"); continue; } else if(pt.xrt.left pt.xrt.right pt.yrt.top pt.yrt.bottom){ xyear=0; year=0; clear(); clock_sz(); hzdy(nowyear,nowmonth);pn=CreatePen(PS_SOLID,2,RGB(255,255,0)); SelectObject(hdc, pn);//选画笔MoveToEx(hdc,5,75,NULL); LineTo(hdc,45,75); SetConsoleCursorPosition(hOut, pos); continue; } }; } } ReleaseDC(hwnd,hdc); }int pd( int year) { int pr=0; if((year%100==0)(year%400==0)) pr=1; else if(year%4==0year%100!=0) pr=1; else pr=0; return pr; } void huizs(int line_head_month) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0;int monthhead={0},mlt={1,1,1}; int endline=0,test=0; int year=0; year=yearbak; for(i=1;iyear;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead=j; for(month=1;monthmonth++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28; else if(month==4||month==6||month==9||month==11) n=30; else n=31; monthhead[month]=(monthhead[month-1]+n)%7; } while(test=5){ for(month=line_head_month;month=(line_head_month+2);mo nth++) { if(month%3==1endline==0) { printf("\t%d月\t\t\t%d月\n",month,month+1,month+2); printf("一二三四五六日一二三四五六日三四五六日\n"); } if(endline==0) { for(k=0;kmonthhead[month-1];k++) printf(" "); j=monthhead[month-1]; } if(endline==0) i=1; else i=mlt[month-1]; for(;ji++,j++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28;%d月一二else if(month==4||month==6||month==9||month==11) n=30; else n=31; if(in) { for(k=0;kk++) printf(" "); break; } printf("%-3.0d",i); } printf(" "); mlt[month-1]=i; if(month%3==0) { printf("\n"); endline=1; } j=0; } test++; } }void hzdy(int year,int nowmonth_hz) { int i=0,j=0,k=0,month=0,n=0,daysum=0,jlw=0; int monthhead={0},mlt={1,1,1}; int endline=0,test=0; for(i=1;iyear;i++) { if(pd(i)) daysum+=366; else daysum+=365; } j=daysum%7; monthhead=j; for(month=1;monthmonth++) { if(pd(year)month==2) n=29; else if(pd(year)==0month==2) n=28;//平年else if(month==4||month==6||month==9||month==11) n=30; elsen=31; monthhead[month]=(monthhead[month-1]+n)%7; } if(pd(year)nowmonth_hz==2) n=29;//闰年else if(pd(year)==0nowmonth_hz==2) n=28;//平年else if(nowmonth_hz==4||nowmonth_hz==6||nowmonth_hz==9||no wmonth_hz==11) n=30;//4,6,9,11月else n=31; printf("\n\n\n\n\n\n\n\n 当前时间:%d年%d月%d日%d时%d分\n\n",nowyear,nowmonth,nowday,hour,min); printf("\t一二三四五六日\n\t"); for(k=0;kmonthhead[nowmonth_hz-1];k++) printf(" "); j=monthhead[nowmonth_hz-1]; for(i=1;ii++,j++) { if(j==7) { printf("\n\t"); j=0; } printf("%-3.0d",i); } printf("\n"); } void clock_sz() { float a,b,c; float x=0,y=0,ex=100,ey=160,radian=0,oldx,oldy,radius=90; float mx=0,my=0,oldmx,oldmy,mradius=40; float hx=0,hy=0,oldhx,oldhy,hradius=20; intkd_r1,kd_r2,kd_radius=170,kd_radius1,old_kd_x,old_kd_y,kd_radi an=0,k=0,q=0,oldk,oldq; HWND hwnd; HANDLE hOut; HDC hdc; *****F C1=RGB(0,0,0),C2=RGB(0,0,0); HBRUSH hbr,hbr1,hbr2; HPENhpn,gpn,rpn,ppn2,ypn,bpn,kdpn,rkdpn,dotpn,blue,black,blkdpn, pkdpn,hpn2; hwnd=GetConsoleWindow(); hdc = GetDC(hwnd);hOut = GetStdHandle(STD_OUTPUT_HANDLE); hbr= CreateSolidBrush(RGB(0,100,0)); hbr1= CreateSolidBrush(C1); hbr2= CreateSolidBrush(RGB(0,0,150)); hpn2=CreatePen(PS_SOLID,1,RGB(255,0,0));rpn=CreatePen(PS_SOLID,1,RGB(255,0,0));hpn=CreatePen(PS_SOLID,1,RGB(0,255,255));blue=CreatePen(PS_SOLID,3,RGB(0,0,255));bpn=CreatePen(PS_SOLID,1,RGB(255,255,255));gpn=CreatePen(PS_SOLID,2,RGB(0,255,0));pkdpn=CreatePen(PS_SOLID,3,RGB(0,255,255));kdpn=CreatePen(PS_SOLID,1,RGB(255,255,0));rkdpn=CreatePen(PS_SOLID,4,RGB(255,0,0));blkdpn=CreatePen(PS_SOLID,6,RGB(0,0,0));black=CreatePen(PS_SOLID,4,C1); ex=400;//时钟圆心位置ey=230;while(kd_radian=360){ if(kd_radian%5==0) { if(kd_radian%90==0){ kd_radius=130; SelectObject(hdc,rkdpn); } else{ kd_radius=125; SelectObject(hdc,pkdpn); } } else { kd_radius=130; SelectObject(hdc, kdpn); kd_radius1=120; } y=kd_radius*sin(kd_radian/180.0*3.14);x=kd_radius*cos(kd_radian/180.0*3.14);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+x,ey+y); y=kd_radius1*sin(kd_radian/180.0*3.14);x=kd_radius1*cos(kd_radian/180.0*3.14); old_kd_x=x; old_kd_y=y; SelectObject(hdc,blkdpn); MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+old_kd_x,ey+old_kd_y); kd_radian+=6; };SetTextColor(hdc,RGB(0,255,0));}TextOut(hdc,ex+kd_radius+8,ey-7,TEXT("3"),1);TextOut(hdc,ex-4,ey+kd_radius+3,TEXT("6"),1); TextOut(hdc,ex-kd_radius-15,ey-5,TEXT("9"),1); TextOut(hdc,ex-7,ey-kd_radius-18,TEXT("12"),2); radius=110;mradius=90;//分针半径hradius=70;//时针半径x=0,y=0; radian=0;SetTextColor(hdc,RGB(0,255,225));////设颜色SetBkColor(hdc,RGB(0,0,0));////设颜色ti2();a=sec*6/180.0*3.14; b=min*6/180.0*3.14;c=(hour*30.0-90.0+(min+15)/2.0)/180.0*3.14; SetTextColor(hdc,RGB(0,255,255)); my=mradius*sin(b); mx=mradius*cos(b); SelectObject(hdc, gpn);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+mx,ey+my); LineTo(hdc,ex+mx,ey+my); hy=hradius*sin(c); hx=hradius*cos(c);SelectObject(hdc, blue);MoveToEx(hdc,ex,ey,NULL); LineTo(hdc,ex+hx,ey+hy); ReleaseDC(hwnd, hdc);。

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++)<>。

CC++程序设计——万年历(完整代码+实验报告)

CC++程序设计——万年历(完整代码+实验报告)

2、主要函数流程图: (1)类的构造函数:用于给类的对象赋值。提示用户输入数据,并具有较强的错误输 入数据检查功能。(参见图 3-1) (2)闰年判断函数:判断哪些年份为闰年。 (图 3-2)
正文 第 2 页(共 18 页)
开 始
开 始
year%4==0

输入待查询的 年份


year%100==0
* ","***** ","***** ","***** ","***** ","***** "," * ","***** ","***** "," * ","***** ","***** ","
"***** ","
=====================公元"<<year<<"年日历====================="<<endl; =====================公元"<<year<<"年日历====================="<<endl;
/*实现 3 维数组图案的输出*/ for(int g=0;g<5;g++) { cout<<" fout<<" for(int i=0;i<4;i++) for(int h=0;h<7;h++) { cout<<ss[g][num[i]][h]; fout<<ss[g][num[i]][h]; } cout<<endl; fout<<endl; } }

万年历c语言代码讲解

万年历c语言代码讲解

万年历c语言代码讲解万年历是一种常见的日历形式,可以显示一年中每一天的日期和星期几。

在计算机编程中,我们可以使用C语言编写一个万年历的程序来实现这个功能。

我们需要了解一个概念:闰年。

闰年是指能被4整除但不能被100整除的年份,或者能被400整除的年份。

闰年的2月份有29天,而普通年份的2月份只有28天。

接下来,我们可以开始编写程序了。

首先,我们需要定义一个结构体来表示日期,结构体中包含年、月和日三个成员变量。

然后,我们可以编写一个函数来判断某一年份是否是闰年。

根据闰年的定义,我们可以使用取余运算符(%)来判断。

接下来,我们需要编写一个函数来计算某一年月的某一天是星期几。

这个函数的核心思想是根据已知的某一天是星期几,然后通过计算得出某一天之后或之前的日期是星期几。

我们可以使用一个数组来保存每个月份的天数,并根据年份是否是闰年来调整2月份的天数。

在计算星期几的过程中,我们可以使用蔡勒公式。

蔡勒公式是一种计算星期几的方法,根据蔡勒公式,我们可以得出某一天是星期几。

具体的计算公式可以在代码中实现,但是根据要求,我们不能输出公式,所以在这里就不展开讲解了。

接下来,我们可以编写一个主函数来调用上述的函数,并输出结果。

在主函数中,我们可以通过用户输入来获取需要查询的年月信息,然后调用函数来计算星期几,并输出结果。

为了使输出结果更加美观,我们可以使用制表符来对齐输出的结果。

在编写主函数的过程中,我们还可以加入一些错误处理的代码,例如判断用户输入的年月是否合法,以及判断计算结果是否正确。

这样可以增加程序的健壮性和用户体验。

我们还可以考虑加入一些额外的功能,例如输出某个月份的日历表格或者某一天所在的周的日期范围等。

这样可以提升程序的实用性和功能性。

通过以上的步骤,我们就可以完成一个简单的万年历程序的编写。

这个程序可以根据用户的输入来计算某一年月的某一天是星期几,并输出结果。

通过这个程序,我们可以更方便地查询任意日期的星期几,从而更好地了解和利用时间。

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语言编程代码

#include <stdio.h>// 函数声明int is_leap_year(int year);int get_first_day_of_year(int year);// 主函数int main() {int year, month, first_day_of_year, first_day_of_month, days_in_month;int i, j, k;printf("请输入年份(例如:2022):");scanf("%d", &year);first_day_of_year = get_first_day_of_year(year);for (month = 1; month <= 12; month++) {printf("%d 年%d 月\n", year, month);printf("日一二三四五六\n");if (month == 2) {if (is_leap_year(year)) {days_in_month = 29;} else {days_in_month = 28;}} else if (month == 4 || month == 6 || month == 9 || month == 11) { days_in_month = 30;} else {days_in_month = 31;}first_day_of_month = (first_day_of_year + (month-1)*28)%7;for (i = 1; i <= first_day_of_month; i++) {printf(" ");}for (j = 1; j <= days_in_month; j++) {printf("%2d ", j);k = (i + j - 1) % 7;if (k == 0) {printf("\n");}}printf("\n");}}// 判断是否闰年int is_leap_year(int year) {return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);}// 计算年份第一天是星期几int get_first_day_of_year(int year) {int first_day = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;first_day = (first_day + 1) % 7;return first_day;}这是一个简单的万年历示例代码,但它不是完整的代码。

c++万年历及公历农历转换源代码2

c++万年历及公历农历转换源代码2

#include <stdio.h>#include <stdlib.h>#include <conio.h>#define X " Sun Mon Tue Wed Thu Fri Sat"#define P printf#define B break#define FP fprintfstruct date /*日期*/{int year;int month;int date;};struct taglunarcal /**/{int basedays;int intercalation;int monthdays[13];}dalist[]={{31,8,0,1,0,0,1,0,1,1,0,1,1,0,1},{50,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{39,0,1,0,1,0,0,1,0,1,0,1 ,1,1,0},{29,5,0,1,0,1,0,0,1,0,0,1,1,0,1},{47,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{35,0,1,1,0,1,1,0,0,1,0,1,0,1,0},{25,4,0,1,1,0,1,0,1,0,1,0,1,0,1},{4 4,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{33,0,1,0,0,1,1,0,1,0,1,1,0,1,0},{22,2,0,1,0,0,1,0,1,0,1,1,1,0,1},{41,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{3 0,6,1,0,1,0,0,1,0,0,1,1,0,1,1},{49,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{37,0,1,1,0,1,0,0,1,0,0,1,0,1,0},{26,5,1,1,0,1,0,1,0,1,0,1,0,0,1},{4 5,0,1,0,1,1,0,1,0,1,0,1,0,1,0},{35,0,0,1,0,1,0,1,1,0,1,0,1,0,0},{23,2,1,0,0,1,0,1,1,0,1,1,0,1,0},{42,0,1,0,0,1,0,1,0,1,1,0,1,1,0},{3 2,7,0,1,0,0,1,0,0,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,0,1,0,1,0,0,1,1,1,0,1},{41,0,1,1,0,1,0,0,1,0,0,1,1,0,0},{30,8,1,1,1,0,1,0,0,1,0,1,1,0,1},{4 9,0,1,1,0,1,0,1,0,1,0,0,1,0,0},{38,0,1,1,0,1,1,0,1,0,1,0,1,0,0},{27,6,0,1,1,0,1,0,1,0,1,0,1,0,0},{46,0,0,1,0,1,0,1,1,0,1,1,0,1,0},{3 6,0,0,1,0,0,1,0,1,0,1,1,1,0,0},{25,4,1,0,1,0,1,0,0,1,1,1,0,1,0},{43,0,1,0,1,0,0,1,0,0,1,1,0,1,0},{32,0,1,0,1,0,0,0,0,1,0,1,0,1,0},{2 1,2,1,1,1,1,0,0,1,0,0,1,0,1,1},{40,0,1,1,0,1,0,1,0,1,0,0,1,0,0}};getleap( int year ) /*1代表闰年*/{if ( year % 400 == 0 )return 1;else if ( year % 100 == 0 )return 0;else if ( year % 4 == 0 )return 1;elsereturn 0;}print(int n){int i;for(i=0;i<n;i++) printf(" ");}int day(int year){long 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; }}solardate(struct date * input) /*公历年第几天*/{int i,number=0,solarcal[12]={31,28,31,30,31,30,31,31,30,31,30,31}; number=getleap(input->year);for(i=0;i<input->month-1;i++){number+=solarcal[i];}return number+input->date;}lunardate(struct date *input)/*农历年第几天*/{int i,leap=0,number=0;if(dalist[input->year-1900].intercalation==0)leap=0;else if(input->month==dalist[input->year-1900].intercalation){printf(" 0 not leap month\n 1 leap month");scanf("%d",&leap);}else if(input->month>dalist[input->year-1900].intercalation) leap=1;for(i=0;i<input->month+leap-1;i++)number+=dalist[input->year-1900].monthdays[i]+29;return number+input->date;}lunarmonth(int year,int *mon){int i,j;mon[0]=dalist[year].monthdays[0]+29;for(i=1,j=1;i<12;i++,j++){if(i==dalist[year].intercalation){mon[i-1]+=dalist[year].monthdays[j]+29;j++;}mon[i]=mon[i-1]+dalist[year].monthdays[j]+29;}}main(){int i,j,k,m,n,f1,f2,year,d,y,ly,cord,greday,lunday,diff,add,leap,tlylm[12],lastylm[12],a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},SolarDays[2][12] = {{31,59,90,120,151,181,212,243,273,304,334,365},{31,60,91,121,152,182,213,244,274,305,335, 366}};char fname[12]={"0"}; FILE *fw;struct date input;do{printf("\n--------------------------------------------\n");printf(" 请选择");printf("\n--------------------------------------------\n");printf(" 1 公历转换成农历");printf("\n--------------------------------------------\n");printf(" 2 农历转换成公历");printf("\n--------------------------------------------\n");printf(" 3 万年历");printf("\n--------------------------------------------\n");printf(" 4 退出");printf("\n--------------------------------------------\n");printf("\n 请选择: 1,2,3,4\n");scanf("%d",&cord);clrscr();switch(cord){case 1:{printf("\n(公历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);/*输入年月日*/y=input.year;greday=solardate(&input);/*公历年第几天*/diff=greday-dalist[y-1900].basedays;if(diff>0)lunarmonth(y-1900,tlylm);else{y-=1;lunarmonth(y-1900,tlylm);diff+=tlylm[11];}for(i=0;tlylm[i]<diff;i++);if(i!=0)diff-=tlylm[i-1];printf("(农历) %d.%d.%d",y,i+1,diff);break;}clrscr();case 2:{printf("\n(农历) 请输入年.月.日(yyyy.mm.dd) \n");scanf("%d.%d.%d",&input.year,&input.month,&input.date);y=input.year;ly=getleap(y);lunday=lunardate(&input);/*农历年第几天*/add=lunday+dalist[y-1900].basedays;if(add-365+ly>0){add-=365+ly;y+=1;}for(i=0;SolarDays[ly][i]<add;i++);if(i!=0)add-=SolarDays[ly][i-1];printf("(公历) %d.%d.%d",y,i+1,add);break;}case 3:{system("cls");P(" 请输入你所要查看的年份:");scanf("%d",&year);fw=fopen(fname,"w+");if(fw==NULL){P(" can not open file."); return;}P(" The calendar of the year %d.\n",year);FP(fw,"The calendar of the year %d.\n",year);d=day(year);if(year%4==0&&year%100||year%400==0) a[2]++;for(i=1;i<=12;i+=2){m=0; n=0; f1=0; f2=0;switch(i){case 1:P(" Januray 1 "); FP(fw," Januray 1 "); B; case 3:P(" March 3 "); FP(fw," March 3 "); B; case 5:P(" May 5 "); FP(fw," May 5 "); B; case 7:P(" July 7 "); FP(fw," July 7 "); B; case 9:P(" September 9 "); FP(fw," September 9 "); B; case 11:P(" Nevember 11 "); FP(fw," Nevember 11 "); B; }print(21);for(k=0;k<21;k++) fprintf(fw," ");switch(i+1){case 2:P(" February 2 "); FP(fw," February 2 ");B; case 4:P(" April 4 "); FP(fw," April 4 ");B;case 6:P(" June 6 "); FP(fw," June 6 ");B; case 8:P(" August 8 "); FP(fw," August 8 "); B; case 10:P(" October 10 "); FP(fw," October 10 ");B; case 12:P(" December 12"); FP(fw," December 12");B;}P("\n");fprintf(fw,"\n");P(X); fprintf(fw,X); print(6);fprintf(fw," "); P(X); fprintf(fw,X);fprintf(fw,"\n"); P("\n");for(j=0;j<6;j++){if(j==0){print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++m); fprintf(fw,"%4d",m);}print(6); fprintf(fw," ");d+=a[i]%7; d%=7;print(d*4); for(k=0;k<d*4;k++) fprintf(fw," ");for(k=0;k<7-d;k++){P("%4d",++n); fprintf(fw,"%4d",n);}P("\n"); fprintf(fw,"\n");}else{for(k=0;k<7;k++){if(m<a[i]){P("%4d",++m); fprintf(fw,"%4d",m);}else{print(4); fprintf(fw,"");}if(m==a[i]) f1=1;}print(6); fprintf(fw," ");for(k=0;k<7;k++){if(n<a[i+1]){P("%4d",++n);fprintf(fw,"%4d",n);}else{print(4); fprintf(fw,"");}if(n==a[i+1]) f2=1;}P("\n"); fprintf(fw,"\n");if(f1&&f2) B;}}d+=a[i+1]%7; d%=7; P(" "); fprintf(fw," "); if(i==5){getch();system("cls");}}fclose(fw);getch();break;}case 4:{exit(0);}}}while(cord<=4);}。

C语言万年历代码

C语言万年历代码

else if(ch=='n'||ch=='N')
{ month+=1;
if(month>12) {month=1;year+=1;}
}
printf("\t\t********e退出 p上一月 n下一月********");
}
void first_set(int *year,int *month)
{ do{
printf ("please input the year(1~9999):");
if (choose=='y'||choose=='Y') main();
}
days_of_month(int x,int y)
{
int z;
switch (y)
{case 1:
case 3:
case 5:
case 7:
case 8:
printf ("please input the month(1~12):");
scanf ("%d",month);
if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");
printf ("\n\n********************************************************************************\n\n");
自己做的日历(C语言)
本帖最后由 kekeyu 于 2010-8-15 16:59 编辑

万年历源代码

万年历源代码
LCD_Write(LCD_COMMAND, 0x04|InputMode); }
//初始化 LCD************************************************************
void LCD_Initial()
{
LcdEn=0; LCD_Write(LCD_COMMAND,0x38);
#define LCD_SHOW
0x04 //显示开
#define LCD_HIDE
0x00 //显示关
#define LCD_CURSOR #define LCD_NO_CURSOR
#define LCD_FLASH #define LCD_NO_FLASH
0x02 0x00
//显示光标 //无光标
{
Time->DateString[0] = '2';
Time->DateString[1] = '0';
Time->DateString[2] = Time->Year/10 + '0';
#include <REG52.H> #include <intrins.h> //#include "LCD1602.h" //#include "DS1302.h"
#define uint unsigned int #define uchar unsigned char sbit DS1302_CLK = P1^7; sbit DS1302_IO = P1^6; sbit DS1302_RST = P1^5;
0x01 0x00
//光标闪动 //光标不闪动

C语言程序设计 输出任意年份的日历

C语言程序设计  输出任意年份的日历
for(q=i1;q<7;q++)/*格式对齐的控制使第二列的日历每行的第一个书从同一位置开始*/
printf("");
printf("");
i2=0;flag2=0;
for(day2=p-(W+t[month-1])%7;day2<=t[month]&&flag2==0;day2++)
{i2++;printf("%4d",day2);
{
if(month<3)
{c=((int)(year-1)/100);
Y=(year-1)-((int)((year-1)/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+13)/5));
W=(w+70)%7;
}
else if(month>=3)
if(i2%7==0) flag2=1;}
printf("\n");
}
}
}
{c=((int)(year/100));
Y=year-((int)(year/100))*100;
w=((int)(c/4))-2*c+Y+((int)(Y/4))+((int)(13*(month+1)/5));
W=(w+70)%7;
}
printf("\n\n%d%d\n",month,month+1);printf("日一二三四五六日一二三四五六\n");i1=W;/*一行一行的输出*/

c语言课程设计报告 万年历 最详细

c语言课程设计报告 万年历 最详细

C语言课程设计报告-----万年历设计人:贾伟涛学号:2013010912班级:13电信应电班指导老师:张伟日期:2014年6月9日内容提要通过大一下学期对C语言的学习,了解到了很多C语言的相关知识。

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

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

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

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

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

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

通过这个小小的系统可以实现很多功能。

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

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

接下来就是我的C 语言课程设计的具体内容来了,大家拭目以待吧!目录一、系统功能和数据说明-----------------------二、问题分析---------------------------------三、程序总体设计及功能结构框图---------------四、程序流程图-------------------------------五、源程序代码-------------------------------六、使用说明---------------------------------七、个人心得---------------------------------八、参考文献---------------------------------一、系统功能和数据说明(一)功能简介在日常生活中能接触到很多不同类型的日历,在日历上我们通常希望它能简单明了的给我们最想要的日期信息。

万年历c语言代码讲解

万年历c语言代码讲解

万年历c语言代码讲解摘要:一、万年历C语言代码讲解简介1.万年历的概念及用途2.C语言代码讲解的重要性二、C语言代码基础1.C语言简介2.C语言基本语法3.C语言的数据类型与变量三、万年历C语言代码实现1.计算闰年2.计算月份的天数3.计算日期的星期4.输出万年历四、万年历C语言代码的优化与拓展1.代码性能优化2.功能的拓展与实现五、总结1.万年历C语言代码讲解的意义2.对编程能力的提升正文:一、万年历C语言代码讲解简介万年历是一种记录了公历日期的工具,它可以帮助我们快速查询公历日期对应的农历、节日、提醒等信息。

C语言是一种广泛应用于计算机领域的编程语言,掌握C语言编程对于学习其他编程语言有很大的帮助。

本文将详细讲解万年历C语言代码的实现过程,帮助读者更好地理解C语言编程。

二、C语言代码基础1.C语言简介C语言是一种高级编程语言,由丹尼斯·里奇(Dennis Ritchie)于20世纪70年代在贝尔实验室开发。

C语言具有良好的性能和可移植性,被广泛应用于操作系统、嵌入式系统、硬件驱动等领域。

2.C语言基本语法C语言的基本语法包括变量声明、数据类型、运算符、控制结构、函数等。

了解这些基本语法对于编写C语言代码至关重要。

3.C语言的数据类型与变量C语言的数据类型包括整型、浮点型、字符型等。

变量是存储数据的容器,通过变量名来表示。

声明变量时需要指定变量的数据类型和存储空间。

三、万年历C语言代码实现1.计算闰年闰年是指公历年份可以被4整除但不能被100整除的年份,或者是可以被400整除的年份。

通过编写一个函数,我们可以判断一个年份是否为闰年。

2.计算月份的天数根据公历规定,每个月的天数不同。

通过编写一个函数,我们可以计算指定月份的天数。

3.计算日期的星期通过编写一个函数,我们可以根据公历日期计算对应的星期。

4.输出万年历根据用户输入的日期范围,输出对应的万年历信息。

四、万年历C语言代码的优化与拓展1.代码性能优化在实现万年历C语言代码的过程中,可以通过优化算法、使用更高效的函数等方式提高代码性能。

万年历的程序代码

万年历的程序代码

万年历的程序代码一年没碰Pascal了,写起来还有点吃力,希望对99级的同学有点帮助. : 程序已编译通过;附2000年年历;: 不足之处请大家批评指出.: 只限参考,不可抄袭.: Program wnl(input,output);: label: again;: var: a:char;: i:integer;: ran,year,all_days,all_years:integer;: days_month,first_month:array[1..12]of integer;: procedure display;: var: i,j,k,l,m,n,c,d,mm,nn:integer;: begin: for j:=0 to 5 do: begin: mm:=1;: nn:=1;: k:=j*2+1;: l:=j*2+2;: m:=first_month[k];: n:=first_month[l];: if m=0 then m:=7;: if n=0 then n:=7;: for i:=1 to 21 do write( );: write(No.,k:2);: for i:=1 to 32 do write( );: writeln(No.,l:2);: for i:=1 to 8 do write( );: writeln(||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|: fri|sat|sun||);: write( ||);: for c:=1 to 7 do if c$#@60;m then write( |) else: begin: write(mm:3,|);: mm:=mm+1;: end;: write(| ||);: for c:=1 to 7 do if c$#@60;n then write( |) else: begin: write(nn:3,|);: nn:=nn+1;: end;: writeln(|);{the first line.}: for d:=1 to 5 do: begin: write( ||);: for c:=1 to 7 do if mm>days_month[k] then write( |) else: begin: write(mm:3,|);: mm:=mm+1;: end;: write(| ||);: for c:=1 to 7 do if nn>days_month[l] then write( |) else: begin: write(nn:3,|);: nn:=nn+1;: end;: writeln(|);: end;: readln;: end;: end;: begin{main}: days_month[1]:=31;: days_month[2]:=28;: days_month[3]:=31;: days_month[4]:=30;: days_month[5]:=31;: days_month[6]:=30;: days_month[7]:=31;: days_month[8 31;: days_month[9]:=30;: days_month[10]:=31;: days_month[11]:=30;: days_month[12]:=31;: writeln(This program may help you to make a calender of the year yo: u input.);: again: year:=0;: ran:=0;: for i:=1 to 12 do first_month[i]:=0;: writeln(Please input the year number:);: readln(year);: if (year mod 400 =0) or ((year mod 100 $#@60;>0) and (year mod 4=0)) then: ran:=1;: days_month[2]:=days_month[2]+ran;: all_years:=year-1;: all_days:=all_years+(all_years div 4)-(all_years div 100)+(all_years : div 400);: first_month[1]:=(all_days+1) mod 7;: for i:=2 to 12 do first_month[i]:=(first_month[i-1]+days_month[i-1]) : mod 7;: display;: writeln(Press enter to continute,Ctrl+C to quit.);: readln;: goto again;: end.{main}: 2000年年历:: This program may help you to make a calender of the year you input. : Please input the year number:2000: No. 1 No. 2: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | | | | 1| 2|| || | 1| 2| 3| 4| 5| 6||: || 3| 4| 5| 6| 7| 8| 9|| || 7| 8| 9| 10| 11| 12| 13||: || 10| 11| 12| 13| 14| 15| 16|| || 14| 15| 16| 17| 18| 19| 20||: || 17| 18| 19| 20| 21| 22| 23|| || 21| 22| 23| 24| 25| 26| 27||: || 24| 25| 26| 27| 28| 29| 30|| || 28| 29| | | | | ||: || 31| | | | | | || || | | | | | | ||: No. 3 No. 4: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | 1| 2| 3| 4| 5|| || | | | | | 1| 2||: || 6| 7| 8| 9| 10| 11| 12|| || 3| 4| 5| 6| 7| 8| 9||: || 13| 14| 15| 16| 17| 18| 19|| || 10| 11| 12| 13| 14| 15| 16||: || 20| 21| 22| 23| 24| 25| 26|| || 17| 18| 19| 20| 21| 22| 23||: || 27| 28| 29| 30| 31| | || || 24| 25| 26| 27| 28| 29| 30||: || | | | | | | || || | | | | | | ||: No. 5 No. 6: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || 1| 2| 3| 4| 5| 6| 7|| || | | | 1| 2| 3| 4||: || 8| 9| 10| 11| 12| 13| 14|| || 5| 6| 7| 8| 9| 10| 11||: || 15| 16| 17| 18| 19| 20| 21|| || 12| 13| 14| 15| 16| 17| 18||: || 22| 23| 24| 25| 26| 27| 28|| || 19| 20| 21| 22| 23| 24| 25||: || 29| 30| 31| | | | || || 26| 27| 28| 29| 30| | ||: || | | | | | | || || | | | | | | ||: No. 7 No. 8: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun||: || | | | | | 1| 2|| || | 1| 2| 3| 4| 5| 6||: || 3| 4| 5| 6| 7| 8| 9|| || 7| 8| 9| 10| 11| 12| 13||: || 10| 11| 12| 13| 14| 15| 16|| || 14| 15| 16| 17| 18| 19| 20|| : || 17| 18| 19| 20| 21| 22| 23|| || 21| 22| 23| 24| 25| 26| 27|| : || 24| 25| 26| 27| 28| 29| 30|| || 28| 29| 30| 31| | | ||: || 31| | | | | | || || | | | | | | ||: No. 9 No.10: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun|| : || | | | | 1| 2| 3|| || | | | | | | 1||: || 4| 5| 6| 7| 8| 9| 10|| || 2| 3| 4| 5| 6| 7| 8||: || 11| 12| 13| 14| 15| 16| 17|| || 9| 10| 11| 12| 13| 14| 15||: || 18| 19| 20| 21| 22| 23| 24|| || 16| 17| 18| 19| 20| 21| 22|| : || 25| 26| 27| 28| 29| 30| || || 23| 24| 25| 26| 27| 28| 29||: || | | | | | | || || 30| 31| | | | | ||: No.11 No.12: ||mon|tur|wed|thr|fri|sat|sun|| ||mon|tur|wed|thr|fri|sat|sun|| : || | | 1| 2| 3| 4| 5|| || | | | | 1| 2| 3||: || 6| 7| 8| 9| 10| 11| 12|| || 4| 5| 6| 7| 8| 9| 10||: || 13| 14| 15| 16| 17| 18| 19|| || 11| 12| 13| 14| 15| 16| 17|| : || 20| 21| 22| 23| 24| 25| 26|| || 18| 19| 20| 21| 22| 23| 24|| : || 27| 28| 29| 30| | | || || 25| 26| 27| 28| 29| 30| 31||: || | | | | | | || || | | | | | | ||: Press enter to continute,Ctrl+C to quit.--。

万年历代码

万年历代码
monWeeks[0]=0;
monWeeks[January] = yDay;
monWeeks[February] = ((monWeeks[January] +monLen[January] )%7);
monWeeks[Match] = ((monWeeks[February] +monLen[February] )%7);
printf("\n****************************************************\n");
printf(" 星期日 星期一 星期二 星期三 星期四 星期五 星期六\n");
//打印星期表头
for(i=0;i<FirstDay_Month;i++)
scanf("%d",&Year); //把输入的年份赋值给变量Year
printf("请输入月份<0~12>: "); //提示输入月份(1~12)
scanf("%d",&Month); //把输入的月份赋值给变量Month
y=Year;
FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几)
}
printf("\n-------------------------------------------------\n");
printf(" %d, %d \n",y,i);
printf("-------------------------------------------------\n");

万年历程序代码

万年历程序代码

/*****************************************************4字LED点阵屏+DS1302万年历电子钟C 程序*******************************************************DS1302 接线图Vcc2 CLK I/O /RST| | | |-------------------| 8 7 6 5 || DS1302 || || 1 2 3 4 |-------------------| | | |VCC1 GND1 脚接+5V 2,3脚32768HZ晶振4脚接地5脚接S51的P02 6脚接S51的P01 7接S51的P008脚接后备电源,可以接老计算机主板上的3.6V电池,也可以通过二级管隔离接一个大容量电解电容电压在2.5V以上即可维持595连级输出数据,138行驱动。

*///(本程序引用网上程序,有点BUG经过修改后可以使用,经过修改调整加上了温度显示功能,节日提醒功能和家人生日提醒功能。

//程序没有有效简化)07电气工程,付春平!//手动添加定时器2寄存器定义sfr T2CON = 0xC8;(special function register)sfr TL2 = 0xCC;sfr TH2 = 0xCD;sfr RCAP2L = 0xCA;sfr RCAP2H = 0xCB;sbit TF2 = T2CON^7;sbit EXF2 = T2CON^6;sbit RCLK = T2CON^5;sbit TCLK = T2CON^4;sbit EXEN2 = T2CON^3;sbit TR2 = T2CON^2;sbit C_T2 = T2CON^1;sbit CP_RL2= T2CON^0;//sbit ET2 =0xAD;#include<A T89x51.H>#include <intrins.h>#define uchar unsigned char#define uint unsigned intunsigned char irtime;//红外用全局变量bit irokk;unsigned char IRcord[2];unsigned char irdata[17];unsigned char data temp_data[2] = {0x00,0x00} ;void Ircordpro(void);uchar code hanzi[]; //汉字字模uchar code hanzi1[]; //汉字字模uchar code timer[18][16]; //0~9数字uchar code sw[]; //138驱动数据void Show_word(); //待机显示按三秒间隔分别显示年、月日、星期、时分秒。

万年历代码

万年历代码
注意:
“Visual Studio 2008 命令提示”自动设置了 Visual C++ 编译器和所需的任何库的正确路径。应使用它而不是使用普通的“命令提示符”窗口。
在命令提示符下,键入notepad simple.cpp,并按 Enter。
在系统提示是否创建新文件时,单击“是”。
在记事本中,键入下列各行:
else
cout<<"\t";
}
cout<<endl;
cout<<"--------------------------------------------------\n";
}
作者:…烟花飘飘…2008-7-9 22:46 回复此发言
--------------------------------------------------------------------------------
使用命名空间
2008要求较严格 .h是C语言里的东西,所以包含头文件时应该用
#include <iostream>
using namespace std;
创建新项目:
在“文件”菜单上,指向“新建”,然后单击“项目”。
在“Visual C++”项目类型中,单击“Win32”,然后单击“Win32 控制台应用程序”。
4 回复:费了一个小时写的◣万年历◢,o(∩_∩)o..烟花飘飘
用API了,不错
ShineFancyRay
作者:120.128.149.*2008-7-9 23:14 回复此发言
--------------------------------------------------------------------------------

C语言实现农历万年历

C语言实现农历万年历

农历数据:
第 23 位 保留
第 22 至 17 位 农历正月初一的年内序数
第 16 至 13 位 闰月
第 12 至 0 位 月份大小信息
因此,农历数据使用 24 个位,即 3 字节。
上述四个块,分别有如下含义:
3 / 48
2016 年全新原创
C 语言实现农历万年历
paradise300
① 保留位始终为 0; ② 农历正月初一距离公历元旦的天数; ③ 0 表示无闰月,1 至 12 表示闰月月份; ④ 从低位到高位分别对应从正月到(闰)十二月的每个月的大小,“1”表 示大月,即该月有 30 天,“0”表示小月,即该月有 29 天。
//1899年农历十月及以后的月份,每月初一在1900年内的序数。 //cPreMonth中分别对应农历的十月、十一月、十二月、正月。 char const cPreMonth[4]={-59,-29,0,30};
//农历月份信息。一年用个字节表示
//+-----------------------------------------------------------------------+
节气数据:
经统计,公历年的首个节气均为“小寒”。
第 47 至 46 位
第 45 至 0 位
小寒的年内序数减 3 从大寒到冬至每个节气 2 个位,表示距上一节气天数
5 / 48
2016 年全新原创
C 语言实现农历万年历
paradise300
其中第一部分,在使用时,两位数据需要加上 3,才能得到小寒的年内序数, 第二部分,第 45 至 44 位,表示了大寒距离小寒的天数,第 43 至 42 位,表示立 春距离大寒的天数,……以此类推。

单片机万年历程序代码

单片机万年历程序代码

单片机万年历程序代码以下是一个示例单片机万年历的程序代码:```c#include <reg51.h>typedef unsigned char uchar;typedef unsigned int uint;sbit K1 = P2^0; // 显示年份sbit K2 = P2^1; // 显示月份sbit K3 = P2^2; // 显示日期uchar code year_tab[] = {31,28,31,30,31,30,31,31,30,31,30,31}; uchar code week_tab[] = {0x06,0x07,0x01,0x02,0x03,0x04,0x05}; uchar year, month, day, week;void delay(uint ms){uint i, j;for(i=ms;i>0;i--)for(j=110;j>0;j--);}uchar getKey(){if(K1==0) {delay(5);if(K1==0)return 1;while(!K1);}if(K2==0) {delay(5);if(K2==0)return 2;while(!K2);}if(K3==0) {delay(5);if(K3==0)return 3;while(!K3);}return 0;}void display(uchar num) {P0 = num;delay(1);P0 = 0x00;}void init(){TMOD=0x01;TH0=0xFC;TL0=0x67;EA=1;ET0=1;TR0=1;}void main(){init();while(1) {uchar key = getKey();if(key == 1) {year++;if(year == 100)year = 0;}else if(key == 2) {month++;if(month == 13)month = 1;}else if(key == 3) {day++;if(day > year_tab[month-1]) { day = 1;}}display(year / 10);display(year % 10);display(month / 10);display(month % 10);display(day / 10);display(day % 10);display(week);}}void timer0() interrupt 1{TH0=0xFC;TL0=0x67;week++;if(week == 7)week = 0;}```该代码的主要思路是通过外部三个按键模拟年、月和日的调节,通过一个定时器不断更新星期的计数,然后将年、月、日和星期分别在数码管上显示出来。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
printf("%d ",p);
}
printf("\n\n");
};break;
default:printf("程序错误");break;
}
}
}
}
}
case 12:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
j=1;
for(i=1;i<x;i++)
{
if((i%4==0 && i%100!=0)||i%400==0)
{
j++;
}
}
j+=365*(x-1);
k=j%7;
for(i=x;i<y;i++)
{
printf(" \t*公元%d年*\n",i);
#include "stdio.h"
main()
{
int x,y,i,j,k=0,p,q;
printf("请输入年份:");
scanf("%d%d",&x,&y);
if(x<=0 || y<=1 || x>=y)
{
printf("输入有误\n");
}else
{
case 10:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
printf("\n\n");
};break;
case 11:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=30;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
printf("\n\n");
};break;
printf("%d ",p);
}
printf("\n\n");
};break;
case 9:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=30;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
printf("\n\n");
};break;
printf("%d ",p);
}
printf("\n\n");
};break;
case 5:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
for(j=1;j<=12;j++)
{
printf("*月份%d月\n",j);
printf("日 一 二 三 四 五 六\n");
printf("--------------------------\n");
switch(j)
{
case 6:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=30;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
case 8:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
}
}else
{
for(p=1;p<=28;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
printf("\n\n");
};break;
printf("%d ",p);
}
printf("\n\n");
};break;
case 2:{
for(q=0;q<k;q++) printf(" ");
if((i%4==0 && i%100!=0)||i%400==0)
{
for(p=1;p<=29;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
case 4:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=30;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
}
printf("\n\n");
};break;
case 3:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
{
k=k%7;
if(k==0) printf("\n" ");
printf("%d ",p);
}
printf("\n\n");
};break;
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
printf("%d ",p);
}
printf("\n\n");
};break;
printf("%d ",p);
}
printf("\n\n");
};break;
case 7:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
case 1:{
for(q=0;q<k;q++) printf(" ");
for(p=1;p<=31;p++,k++)
{
k=k%7;
if(k==0) printf("\n");
if(p<10) printf(" ");
相关文档
最新文档