1,用c语言编制一个万年历

#include#include char* month_str[]={"january","february","march","april","may","june","july","august","september","october","november","december"}; char* week[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"}; int isleapyear(int year) /*find out the year is leap year or not*/ { if((year%4==0&&year%100!=0)||(year%400==0)) return 1; else return 0; } int month_day(int year,int month) { int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; if(isleapyear(year)&&month==2) return 29; else return(mon_day[month-1]); } int daysearch(int year,int month,int day) /*search what day this day is*/ { int c=0; float s; int m; for(m=1;m

用c语言编制一个万年历

2,求万年历代码 一定要C的 最好全面点

一个万年历的C++实现代码 #include < iostream > #include < iomanip > using namespace std; int FistDayofYear( int y); int DaysofMonth( int m); void PrintMonth( int m); void PrintHead( int m); bool LeapYear( int y); int WeekDay,year; void main() { INPUT: cerr << " 请输入年份(>1): " ; cin >> year; WeekDay = FistDayofYear(year); cout << " \n\n " << year << " 年\n " ; cout << " ========================================================== " ; for ( int a = 1 ;a < 13 ;a ++ ) PrintMonth(a); cout << endl; int r = 0 ,u = 0 ; cout << " 继续打1,退出打0 : " ; cin >> r; if (r > u) goto INPUT; else goto END; END:; } void PrintMonth( int m) { PrintHead(m); int day = DaysofMonth(m); for ( int i = 1 ;i <= day;i ++ ) { cout << setw( 5 ) << i; WeekDay = (WeekDay + 1 ) % 7 ; if (WeekDay == 0 ) { cout << endl; cout << setw( 5 ) << " " ; } } } void PrintHead( int m) { cout << " \n\n " << setw( 5 ) << m; cout << " 月 日 一 二 三 四 五 六 \n " ; cout << setw( 5 ) << " " ; for ( int i = 0 ;i < WeekDay;i ++ ) cout << setw( 5 ) << " " ; } int DaysofMonth( int m) { switch (m) { case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 : return 31 ; case 4 : case 6 : case 9 : case 11 : return 30 ; case 2 : if (LeapYear(year)) return 29 ; else return 28 ; } return 0 ; } bool LeapYear( int y) { return (y % 4 == 0 && y % 100 != 0 || y % 400 == 0 ); } int FistDayofYear( int y) { long m; m = y * 365 ; for ( int i = 1 ;i < y;i ++ ) m += LeapYear(i); return m %= 7 ; }

求万年历代码 一定要C的 最好全面点

3,c语言中编写万年历的代码要用到那些函数

#include"stdio.h"#define YES 1#define NO 0int isleap(int year) int leap=NO; if(year%4==0 && year%100!=0 || year%400==0) leap = YES; return leap;}int week_of_firstday(int year) int n; n=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7; return n;}int main() int year,month,day,weekday,len_of_month,i; printf("请输入年份:"); scanf("%d",&year); weekday=week_of_firstday(year); for(month=1;month<=12;month++) printf("\n"); printf(" %d年%d月\n",year,month); printf("---------------------\n"); printf("日 一 二 三 四 五 六\n"); printf("---------------------\n"); for(i=0;i<weekday;i=i+1) printf(" "); if(month==4||month==6||month==9||month==11) len_of_month=30; else if(month==2) if(isleap(year)) len_of_month=29; else len_of_month=28; } else len_of_month=31; for(day=1;day<=len_of_month;day++) if(day>9) printf("%d ",day); else printf("%d ",day); weekday++; if(weekday==7) weekday=0; printf("\n"); } } printf("\n");}return 0;}
到底在循环什么 很好理解啊。你具体哪句不理解? 如果通篇要翻译的话,我的翻译也毫无作用。
#includeint monthday(int,int); int isleapyear(int); main() { int days,weekday,year,month=1,d,i; printf("please input the year:\n"); scanf("%d",&year); days=year-1+(year-1)/400+(year-1)/4-(year-1)/100; while(month<=12){ printf("\t\t\t%d-%d\n",year,month); printf("sun\tmon\ttues\twed\tthur\tfir\tsat\n"); d=1,i=1; weekday=(days+1)%7; while(i<=weekday) { printf("\t"); i++; } while(d<=monthday(month,year)) { weekday=(days+1)%7; if(weekday==6) printf("%d\n",d); else printf("%d\t",d); if(d==monthday(month,year)) printf("\n"); d++; days++; } month++; } system("pause"); return 0; } int monthday(int month, int year) { switch(month){ case 1:case 3:case 5:case 7:case 8:case 10:case 12: return 31; break; case 4: case 6:case 9:case 11: return 30; break; case 2: if((isleapyear(year))==1) return 29; else return 28; break; } } int isleapyear(int year) { if((year%4==0)&&(year%100!=0)) return 1; if(year%400==0) return 1; return 0; }

c语言中编写万年历的代码要用到那些函数

4,求c语言万年历程序

#include #include #include long year; int month,day,error_input; char s[100]; int monthdays[12]={31,28,31,30,31,30,31,31,30,31,30,31}; void inputdate(){ long n[3]={0,0,0},k=0,i,len; error_input=-1; printf("Please input the year[,month[,day]]:(Enter Q to quit)\n"); gets(s); len=strlen(s); printf("%d\n",strcmp(s,"Q")); if(strcmp(s,"Q")==0) {error_input=0;return;} if(!isdigit(s[0])||!isdigit(s[len-1])) {error_input=1;return;} for(i=0;iif(!isdigit(s[i])) {if(isdigit(s[i-1])) k++;if(k>2) {error_input=1;return;}} else n[k]=n[k]*10+s[i]-48; } year=n[0]; if(!(year%4)&&(year%100)||!(year%400)) monthdays[1]=29; else monthdays[1]=28; if(n[1]>12) {error_input=1;return;} if(n[2]>monthdays[n[1]-1]) {error_input=1;return;} month=n[1]; day=n[2]; } void printCala(){ int countyear,countday=0,weekflag,i,j,k,c; int startmon,endmon,year1; year1=year-1; countyear=(year1-year1%4)/4-(year1-year1%100)/100+(year1-year1%400)/400; weekflag=(countyear*366+(year-1-countyear)*365+1)%7-1; if(month==0) {startmon=1;endmon=12;} else {startmon=month;endmon=month;} for(k=1;k weekflag=(weekflag+monthdays[k-1])%7; for(k=startmon;k<=endmon;k++) { printf("\n %ld year ",year); switch(k) { case 1: printf("January\n");break; case 2: printf("February\n");break; case 3: printf("March\n");break; case 4: printf("April\n");break; case 5: printf("May\n");break; case 6: printf("June\n");break; case 7: printf("July\n");break; case 8: printf("August\n");break; case 9: printf("September\n");break; case 10: printf("October\n");break; case 11: printf("November\n");break; case 12: printf("December\n");break; } printf("___________________________\n"); printf("Sun Mon Tue Whe Thr Fri Sat\n"); if(weekflag!=0) for(countday=0,j=0;j {printf(" "); countday++;} for(i=1;i<=monthdays[k-1];i++) {if(countday>0&&countday%7==0) printf("\n"); printf("%3d ",i); countday++;} weekflag=(weekflag+monthdays[k-1])%7; printf("\n___________________________\n"); } } int main() { inputdate(); while(error_input!=0) { if(error_input==1) printf("Input ERROR! Please input again:\n"); else printCala(); inputdate(); } }

5,用C语言做一个万年历紧急啊求代码

# include <stdio.h># define N 2012int main() int month_(int x,int y);void p_(int x,int y,int z);int year,month,year_days,month_days,sum_days;for(;;) for(;;) scanf("%d",&year); if(year>=1990) break; }for(;;) scanf("%d",&month); if(month>0&&month<13) break; } year_days=year_(year); printf("year_days=%3d\n",year_days); month_days=month_(month,year); printf("month_days=%3d\n",month_days); if(year>=N) sum_days=year_days+month_days; else sum_days=year_days-month_days;p_(sum_days,month,year); } return 0;}int year_(int x)//判断期间有几个闰年并且求出期间天数 功能函数 有参 有返回值 int m,j=0,k=0,z=-1; if(x-i==0) z=0; else if(x-i>0) if(m%4==0||m%400==0) ++j; z=j*366+(x-i-j)*365; } else if(m%4==0||m%400==0) ++k; z=k*366+(i-x-k)*365; } return z;}int month_(int x,int y)//判断月份并计算天数 功能函数 有参 有返回值 switch(x) case 2 : z= 31; break; case 3 : z= 31+28; break; case 4 : z= 31+28+31; break; case 5 : z= 31+28+31+30; break; case 6 : z= 31+28+31+30+31; break; case 7 : z= 31+28+31+30+31+30; break; case 8 : z= 31+28+31+30+31+30+31; break; case 9 : z= 31+28+31+30+31+30+31+31; break; case 10 : z= 31+28+31+30+31+30+31+31+30; break; case 11 : z= 31+28+31+30+31+30+31+31+30+31; break; case 12 : z= 31+28+31+30+31+30+31+31+30+31+30; break; }if(x>2&&(y%4==0||y%400==0)) return z+1; else return z+0;}void p_(int x,int y,int z)//输出函数 if(z%4!=0||z%400!=0) if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) monthdays=31; else if(y==2) monthdays=28; else monthdays=30;else if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) monthdays=31; else if(y==2) monthdays=29; else monthdays=30;if(z>=N) j=x%7; else j=7-x%7; printf("%5s%5s%5s%5s%5s%5s%5s\n","日"," 一","二","三","四","五","六");//根据系统不一样 自己调节间距保持和日期对其 for(i=0;i<j;i++) printf("%5s"," "); for(i=1;i<=monthdays;i++) if((j+i)%7==0) printf("\n"); } printf("\n"); printf("\n");}

6,万年历的C语言程序

最低0.27元/天开通百度文库会员,可在文库查看完整内容>原发布者:思无邪liyaf万年历C语言代码#includemain(){for(;;){intyear,month,a,b,c,m,n=28;/*定义变量*/longe;printf("请输入年份");scanf("%d",&year);e=year;e--;/*前一年*/e=(e*365+e/4)%7;/*计算这一年的第一天是星期几*/m=e;/*把第一天的日期赋给m*/if((year%4==0)||(year%100!=0)&&(year%400!=0))/*如果是闰年*/n++;printf("%d的日历:",year);for(month=1;month<=12;month++){if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)/*这几个月每个月都是31天*/{c=0;printf("\n");printf("%d月\n",month);printf("日一二三四五六\n");for(b=1;b<=m;b++){c++;printf("");/*从星期日开始到这个月开始的那天前都是空的*/}for(a=1;a<=31;a++){c++;if(c%7-1==0&&c!=1)/*判断一行是否已排满,满了就要换行*/printf("\n");if(a<10)/*如果是小于10,空一格,大于10,前后空*/printf("");printf("%d",a);m++;if(m==7)/*一行排满,开始换行。(指的是这个月的最后一行)*/m=0;}printf("\n");}else{if(month==4||month==6||month==9||month==11||month==2){if(month==2)/*判断2月份*/{c=0;printf("\n");prin
#include <iostream.h>#define YES 1 // 定义符号常数"是"#define NO 0 // 定义符号常数"否" // 函数 isleap(): 判断某年是否闰年int isleap(int year) int leap = NO; if(year%4==0 && year%100!=0 || year%400==0) leap = YES; return leap;}// 函数 week_of_newyears_day(): 求元旦是星期几int week_of_newyears_day(int year) int n = year-1900; n = n+(n-1)/4+1; // 要n-1是因为1904是闰年,但是只有在1905年才能才能将其2月的多的一天加上!! n = n%7; // 多的几天要以7作为循环!!!! return n;}// 主函数: 打印年历int main() int year, month, day, weekday, len_of_month, i; cout << "Please input year: "; cin >> year; // 打印年历 cout << endl << year << endl; // 打印年份 weekday = week_of_newyears_day(year); // 求元旦是星期几 for(month=1; month<=12;month=month+1) // 打印12个月的月历 cout << endl << month << endl; cout << "---------------------------------" << endl; cout << "SUN MON TUE WED THU FRI SET" << endl; cout << "---------------------------------" << endl; for(i=0;i<weekday;i=i+1) // 找当月1日的打印位置 cout << " "; if(month==4 || month== 6 || month==9 || month==11) len_of_month = 30; else if(month==2) if(isleap(year)) len_of_month = 29; else len_of_month = 28; } else len_of_month = 31; for(day=1;day<=len_of_month;day=day+1) // 打印当月日期 if(day>9) cout << day << " "; else cout << day << " "; weekday = weekday+1; if(weekday==7) // 打满一星期应换行 weekday = 0; cout << endl; } } cout << endl; // 打完一月应换行 } return 0;}
#include<stdio.h>longintf(intyear,intmonth)if(month<3)returnyear-1;elsereturnyear;}longintg(intmonth)if(month<3)returnmonth+13;elsereturnmonth+1;}longintn(intyear,intmonth,intday)/*n=1461*f(年、月)/4+153*g(月)/5+日*/return1461l*f(year,month)/4+153l*g(month)/5+day;}intw(intyear,intmonth,intday)/*w=(n-621049)%7(0<=w<7)*/return(int)((n(year,month,day)%7-621049l%7+7)%7);}intdate[12][6][7];intday_tbl[][12]=main()intyear;/*年*/chartitle[]="sunmontuewedthufrisat";clrscr();printf("pleaseinputtheyearwhosecalendaryouwanttoknow:");/*输入年*/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|==================thecalendarofyear%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]);elseprintf("");printf("");/*输出十个空白符*/for(k=0;k<7;k++)if(date[i+6][j][k])printf("%4d",date[i+6][j][k]);elseprintf("");printf("|\n|");}/*scanf("%*c");/*键入回车输出下一个月的日历*/}puts("=================================================================|");puts("\npressanykeytoquit...");getch();}

文章TAG:万年  万年历  代码  c语言  万年历代码  
下一篇