资讯

展开

万年历程序,万年历C语言程序

作者:本站作者

1,万年历C语言程序

#include <stdio.h>long int f(int year,int month) if(month<3) return year-1; else return year;}long int g(int month) if(month<3) return month+13; else return month+1;}long int n(int year,int month,int day) /*N=1461*f(年、月)/4+153*g(月)/5+日*/ return 1461L*f(year,month)/4+153L*g(month)/5+day;}int w(int year,int month,int day) /*w=(N-621049)%7(0<=w<7)*/ return(int)((n(year,month,day)%7-621049L%7+7)%7);}int date[12][6][7];int day_tbl[ ][12]= main() int year;/*年*/ char title[]="SUN MON TUE WED THU FRI SAT";clrscr();printf("Please input the year whose calendar you want to know: ");/*输入年*/scanf("%d%*c",&year);/*输入年份值和掠过值后的回车*/sw=w(year,1,1);leap=year%4==0&&year%100||year%400==0;/*判闰年*/for(i=0;i<12;i++) for(j=0;j<6;j++) for(k=0;k<7;k++) date[i][j][k]=0;/*日期表置0*/for(i=0;i<12;i++)/*一年十二个月*/ for(wd=0,day=1;day<=day_tbl[leap][i];day++) date[i][wd][sw]=day; sw=++sw%7;/*每星期七天,以0至6计数*/ if(sw==0) wd++;/*日期表每七天一行,星期天开始新的一行*/ } printf("\n|==================The Calendar of Year %d =====================|\n|",year);for(i=0;i<6;i++) for(wd=0,k=0;k<7;k++)/*日期表的第六行有日期,则wd!=0*/ wd+=date[i][5][k]+date[i+6][5][k]; wd=wd?6:5; printf("%2d %s %2d %s |\n|",i+1,title,i+7,title); for(j=0;j<wd;j++) printf(" ");/*输出四个空白符*/ /*左栏为第i+1月,右栏为第i+7月*/ for(k=0;k<7;k++) if(date[i][j][k]) printf("%4d",date[i][j][k]); else printf(" "); printf(" ");/*输出十个空白符*/ for(k=0;k<7;k++) if(date[i+6][j][k]) printf("%4d",date[i+6][j][k]); else printf(" "); printf(" |\n|"); } /*scanf("%*c");/*键入回车输出下一个月的日历*/}puts("=================================================================|");puts("\n Press any key to quit...");getch();}

万年历程序,万年历C语言程序

2,万年历程序查询

12345678910111213141516171819202122232425262728293031323334353637#include <iostream>#include "Calendar.h"using namespace std;int main(int argc, char *argv[]) CCalendar cal; int iCurSel = 0; while (1) cout<<"日历查询"<<endl<<endl; cout<<"请选择操作:"<<endl<<endl <<"1. 距离今天的天数计算"<<endl <<"2. 农历查询"<<endl <<"3. 节气查询"<<endl<<endl; cout<<"选择:>"; cin>>iCurSel; switch (iCurSel) case 1: cal.GetDays(); system("pause"); break; case 2: cal.GetNongli(); system("pause"); break; case 3: cal.GetJieqi(); system("pause"); break; default: cout<<"无效的操作,请重新输入"; } system("cls"); } return 0;}详细代码请看这里:wqmcC语言版本的请看这里:n51c1940至2040(C语言版本)下载:olaf

万年历程序,万年历C语言程序

3,编写一个万年历的程序

#include int leap (int year) {if(year%4==0&&year%100!=0||year%400==0) return 1; else return 0; } 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; } int firstday(int month,int year) {int w; w=(1+2*month+3*(month+1)/5+year+year/4+year/400-year/100)%7+1; return w; } main() {int i,j=1,k=1,a,b,month,year; printf("\n input month and year:\n"); scanf("%d%d",&month,&year); b=days_month(month,year); a=firstday (month,year); 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++; } } } getch();
好多塞
你试试这个,不过没有农历节气和农历年月日 using system; using system.collections.generic; using system.text; namespace year { class program { static void main(string[] args) { console.writeline("*************************欢迎使用万年历*************************\n\n"); console.write("请选择年份:\t"); int year = int.parse(console.readline()); console.write("\n请选择月份\t"); int month = int.parse(console.readline()); bool w; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { w = true; } else { w = false; } int day = 0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: day = 31; break; case 4: case 6: case 9: case 11: day = 30; break; case 2: if (w == true) { day = 29; } else { day = 28; } break; } int b = 0; for (int i = 1900; i < year; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { b = b + 366; } else { b = b + 365; } } for (int i = 1; i < month; i++) { switch (i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: b = b + 31; break; case 4: case 6: case 9: case 11: b = b + 30; break; case 2: if (w == true) { b = b + 29; } else { b = b + 28; } break; } } int fristdayofmonth = 1 + b % 7; if (fristdayofmonth == 7) { fristdayofmonth = 0; } console.writeline("\n\n星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六"); for (int i = 0; i < fristdayofmonth; i++) { console.write("\t"); } for (int i = 1; i <= day; i++) { console.write("万年历程序,万年历C语言程序\t",i); if ((fristdayofmonth + i) % 7 == 0) { console.writeline(); } } console.readline(); } } 这是用java编写的 }

万年历程序,万年历C语言程序

4,编写一个万年历程序

你试试这个,不过没有农历节气和农历年月日 using System; using System.Collections.Generic; using System.Text; namespace Year { class Program { static void Main(string[] args) { Console.WriteLine("*************************欢迎使用万年历*************************\n\n"); Console.Write("请选择年份:\t"); int year = int.Parse(Console.ReadLine()); Console.Write("\n请选择月份\t"); int month = int.Parse(Console.ReadLine()); bool w; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { w = true; } else { w = false; } int day = 0; switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: day = 31; break; case 4: case 6: case 9: case 11: day = 30; break; case 2: if (w == true) { day = 29; } else { day = 28; } break; } int b = 0; for (int i = 1900; i < year; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { b = b + 366; } else { b = b + 365; } } for (int i = 1; i < month; i++) { switch (i) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: b = b + 31; break; case 4: case 6: case 9: case 11: b = b + 30; break; case 2: if (w == true) { b = b + 29; } else { b = b + 28; } break; } } int fristDayOfMonth = 1 + b % 7; if (fristDayOfMonth == 7) { fristDayOfMonth = 0; } Console.WriteLine("\n\n星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六"); for (int i = 0; i < fristDayOfMonth; i++) { Console.Write("\t"); } for (int i = 1; i <= day; i++) { Console.Write("万年历程序,万年历C语言程序\t",i); if ((fristDayOfMonth + i) % 7 == 0) { Console.WriteLine(); } } Console.ReadLine(); } } 这是用java编写的 }
文章TAG:万年历程序  万年历C语言程序  万年  万年历  历程  
相关教程
猜你喜欢