编程日历教程(c语言编程输出日历)

2023-12-30 12:41:12 数码极客 bianji01

 

C语言年历显示程序设计

#inclUde

#include

#include

char*month[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nev","Dec"};

char*week[]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

intj_leapyear(intyear)//定义函数检测输入年份是否为闰年

if((/*year%400==0*/year%4==0&&year%100!=0)||(year%400==0))

return(1);

//elseif(year%4==0&&year%100!=0)

//return(1);

elsereturn0;

intmonth_day(intyear,intmonth)//检测该年月份有多少天

intmon_day[]={31,28,31,30,31,30,31,31,30,31,30,31};

if(j_leapyear(year)&&month==2)

return29;

elsereturn(mon_day[month-1]);

intj_week(intyear,intmonth,intday)//检测该天是星期几

intd=0,i;//d表示该天在该年份的累计天数

intw;

/*intmonth_day[]={31,28,31,30,31,30,31,31,30,31,30,31};

if(j_leapyear(year)==1)

month_day[1]=29;

for(i=0;i

d+=month_day[i];

d=d+day;*/

for(i=1;i

d+=month_day(year,i);

d+=day;

w=(year-1)+(int)(year-1)/4-(int)(year-1)/100+(int)(year-1)/400+d;//网上公式

return((int)w%7);

inTAllyear(intyear)//输出全年日历

inti,j,b;

printf("\n%d日历",year);

for(i=1;i<=12;i++)

printf("\n\n\t%s\n",month[i-1]);

//printf("7123456\n");

printf("SMTWTFS\n");

b=j_week(year,i,1);

for(j=1;j<=month_day(year,i)+b;j++)

if(j<=b)

printf("");

elseif(j-b<10)

printf("%2d",j-b);

elseprintf("%2d",j-b);

//elseprintf("%2d",j-b);

if(j%7==0)

putchar(\n);

putchar(\n);

return0;

voidmonth_print(intyear,intmonth)//输入一个年月,输出这个月的日历

inti,c,d;

c=month_day(year,month);

printf("\n\n%d年%d月日历\n",year,month);

printf("SMTWTFS\n");

d=j_week(year,month,1);

for(i=1;i<=c+d;i++)

if(i<=d)

printf("");

elseprintf("%2d",i-d);

if(i%7==0)

putchar(\n);

putchar(\n);

intjisuan_day(intyear,intmonth,intday,intx,inty,intz)//输入年月日,输出距x年y月z日有多少天,星期几,以及是否是公历节日

inti,a,b,c=0,d=0,days=0,m=0,n=0,t;

a=year>=x?year:x;

b=year

if(a>b)

for(i=b+1;i

c+=j_leapyear(i);

elsec=0;

if(year!=x)

d=a-b-1;

elsed=0;

m=365*d+c;

if(year

for(i=month;i<=12;i++)

n+=month_day(year,i);

days=m+n+z-day;

elseif(year>x)

for(i=y;i<=12;i++)

n+=month_day(x,i);

for(i=1;i

n+=month_day(year,i);

days=m+n+day-z;

for(i=month>=y?y:month;i<(month>=y?month:y);i++)

n+=month_day(x,i);

days=ABs(day-z)+n;//输出距离y月z日有多少天

printf("这天离%d年%d月%d有%d天\n",x,y,z,days);

t=j_week(year,month,day);

if(t==0)//输出星期几

printf("这天星期日");

elseif(t==1)

printf("这天星期一");

elseif(t==2)

printf("这天星期二");

elseif(t==3)

printf("这天星期三");

elseif(t==4)

printf("这天星期四");

elseif(t==5)

printf("这天星期五");

elseif(t==6)

printf("这天星期六");

putchar(\n);

if(month==1&&day==1)

printf("这天是元旦节");

elseif(month==2&&day==14)

printf("这天是情人节");

elseif(month==3&&day==8)

printf("这天是妇女节");

elseif(month==3&&day==12)

printf("这天是植树节");

elseif(month==4&&day==1)

printf("这天是愚人节");

elseif(month==4&&day==4)

printf("这天是清明节");

elseif(month==5&&day==1)

printf("这天是劳动节");

elseif(month==6&&day==1)

printf("这天是儿童节");

elseif(month==8&&day==1)

printf("这天是建军节");

elseif(month==9&&day==10)

printf("这天是教师节");

elseif(month==10&&day==1)

printf("这天是国庆节");

elseif(month==12&&day==25)

printf("这天是圣诞节");

elseprintf("这天不是特殊节日");

putchar(\n);

returndays;

voidfish_or_net(intyear,intmonth,intday)//判断是打鱼还是晒网

intq;

inti,a,b,c=0,d=0,days=0,m=0,n=0;

a=year>=1990?year:1990;

b=year<1990?year:1990;

if(a>b)

for(i=b+1;i

c+=j_leapyear(i);

elsec=0;

if(year!=1990)

d=a-b-1;

elsed=0;

m=365*d+c;

if(year<1990)

for(i=month;i<=12;i++)

n+=month_day(year,i);

days=m+n+1-day;

elseif(year>1990)

for(i=1;i<=12;i++)

n+=month_day(1990,i);

for(i=1;i

n+=month_day(year,i);

days=m+n+day-1;

for(i=month>=1?1:month;i<(month>=1?month:1);i++)

n+=month_day(1990,i);

days=abs(day-1)+n;//先确定这天离1990年1月1日有多少天

q=days%5+1;

if(q==1||q==2||q==3)//判断打鱼还是晒网

printf("渔人今天打鱼");

elseprintf("渔人今天晒网");

putchar(\n);

/*intmain()//这部分内容用来校检

intj_leapyear(intyear);

intmonth_day(intyear,intmonth);

intj_week(intyear,intmonth,intday);

intallyear(intyear);

voidmonth_print(intyear,intmonth);

intjisuan_day(intyear,intmonth,intday,intx,inty,intz);

voidfish_or_net(intyear,intmonth,intday);

intx,y,z,year,month,day;

//allyear(2015);

//month_print(2016,12);

printf("请输入今天的日期(按年,月,日输入,如2016,1,14表示2016年1月14日):");

scanf("%d,%d,%d",&x,&y,&z);

printf("\n请随便输入一个日期,格式同上:");

scanf("%d,%d,%d",&year,&month,&day);

jisuan_day(year,month,day,x,y,z);

//fish_or_net(x,y,z);

return0;

}//这部分内容是用来检测上述函数是否出错的

intmain()

intj_leapyear(intyear);

intmonth_day(intyear,intmonth);

intj_week(intyear,intmonth,intday);

intallyear(intyear);

voidmonth_print(intyear,intmonth);

intjisuan_day(intyear,intmonth,intday,intx,inty,intz);

voidfish_or_net(intyear,intmonth,intday);//函数声明

intoption,year,month,day,x,y,z;

charny;

system("color1f");

while(1)

printf("\n\n\t欢迎来到由...编写的程序\n\n");

printf("请选择您需要的服务,输入编号回车结束\n");

printf("1.输入一个年份,输出该年的日历\n");

printf("2.输入年月,输出这个月的日历。\n");

printf("3.输入年月日,输出据今天还有多久,星期几,是否是公历节日。\n");

printf("4.某人自1990年1月1日开始打鱼,“三天打鱼,两天晒网”,输入一个1990年以后的日期,输出他这一天是打鱼还是晒网。\n");

printf("5.退出\n");

scanf("%d",&option);

switch(option)//switch分支结构

case1:

while(1)//while循环,后面的1是常数,表示一直到break才结束循环

printf("请输入一个年份:");

scanf("%d",&year);

allyear(year);

printf("你想继续查询日历么?(y表示继续,n表示结束)");

scanf("%c",&ny);

if(ny==n)

break;

break;

case2:

while(1)

printf("输入年月:");

scanf("%d,%d",&year,&month);

month_print(year,month);

printf("你想继续查询日历么?(y表示继续,n表示结束):");

scanf("%c",&ny);

if(ny==n)

break;

break;

case3:

while(1)

printf("输入年月日:");

scanf("%d,%d,%d",&year,&month,&day);

printf("请输入今天的日期:");

scanf("%d,%d,%d",&x,&y,&z);

jisuan_day(year,month,day,x,y,z);

printf("你想继续查询么?(y表示继续,n表示结束):");

scanf("%c",&ny);

if(ny==n)

break;

break;

case4:

while(1)

printf("输入1990年1月1日以后的一个日期:");

scanf("%d,%d,%d",&year,&month,&day);

fish_or_net(year,month,day);

printf("你想继续查询渔人是打鱼还是晒网么?(y表示继续,n表示结束):");

scanf("%c",&ny);

if(ny==n)

break;

break;

case5:

while(1)

printf("确认么?y表示是的,n表示不是");

scanf("%c",&ny);

if(ny==y)

exit(1);//表示退出程序

elseif(ny==n)

break;

break;

default:printf("对不起,暂时没有这个服务");

break;

return0;

万年历 编程

#includevoid PrintMonthCalender(int startDay,int days);/*函数原型*/int GetWeekDay(int year,int month);/*函数原型*/int GetMonthDays(int year,int month);/*函数原型*/int month,year;/*定义变量*/printf("input the year and month:");scanf("%d-%d",&year,&month);/*读入变量*/printf("\t\t\t%d-%d\n",year,month);printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");/*打印日历表头*/PrintMonthCalender(GetWeekDay(year,month),GetMonthDays(year,month));/*调用函数子程序,打印出某年某月日历*/return 0;/*定义打印日历子程序*/void PrintMonthCalender(int startDay,int days)int k=0,n=1;while(kplease input the year whose calendar you want to know:\n");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;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;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+=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;jCMp(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;i2) {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;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

C++万年历编程(加急)

用C语言编写桌面日历及过程报告

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告