您的位置:

c语言课程设计简易万年历,C语言设计万年历

本文目录一览:

用c语言设计一个简单的万年历怎么写代码

#include"stdio.h"#include"stdlib.h"main(){intYear,Month;//年、月intFirstDay_Year,FirstDay_Month;//某年的第一天是星期几,某年某月的第一天是星期几(范围是0~6,其中0代表星期日)intIsLeapYear;//是否为闰年,0表示不是闰年,1表示是闰年inti,d,y;//临时变量charYN;//YesNo,程序是否要继续intDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//Days[1~12]存储每个月有多少天,其中二月的天数是可变的(闰年29天,平年28天),这里初始化为28天printf("C语言简单万年历\n");//打印标题XunHuan://循环标号(可以通过goto跳转到这里)printf("请输入年份:");//提示输入年份(0~9999)scanf("%d",Year);//把输入的年份赋值给变量Yearprintf("请输入月份:");//提示输入月份(1~12)scanf("%d",Month);//把输入的月份赋值给变量Monthy=Year;FirstDay_Year=5*(y/4)+(y%4)-(y/100)+(y/400);//蔡勒公式(计算某年的第一天是星期几)IsLeapYear=(y%4==4y%100!=100||y%400==0)?1:0;//判断是否为闰年Days[2]=(IsLeapYear==1)?29:28;//闰年二月29天,非闰年二月28天for(i=1,d=0;i

用C语言制作万年历

TC 2.0

/* welcome to use the WanNianLi system!

Copyright @ 2005 KongXinCai All rights reserved!:):):)*/

#includestdio.h

#includestdlib.h

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==0year%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;mmonth;m++)

c=c+month_day(year,m);

c=c+day;

s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;

return ((int)s%7);

}

int PrintAllYear(int year)/*print the all year*/

{

int temp;

int i,j;

printf("\n\n%d Calander\n",year);

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

{

printf("\n\n%s(%d)\n",month_str[i-1],i);

printf("0 1 2 3 4 5 6 \n");

printf("S M T W T F S \n\n");

temp=DaySearch(year,i,1);

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

{

if(j-temp=0)

printf(" ");

else if(j-temp10)

printf("%d ",j-temp);

else

printf("%d ",j-temp);

if(j%7==0)

printf("\n");

}

}

return 0;

}

int main()

{

int option,da;

char ch;

int year,month,day;

printf("Copyright @ 2005 TianQian All rights reserved!:):):)");

printf("\n\nWelcome to use the WanNianLi system!\n");

while(1)

{

printf("\nPlease select the service you need:\n");

printf("\n1 Search what day the day is");

printf("\n2 Search whether the year is leap year or not");

printf("\n3 Print the calander of the whole year");

printf("\n4 Exit\n");

scanf("%d",option);

switch(option)

{

case 1:

while(1)

{

printf("\nPlease input the year,month and day(XXXX,XX,XX):");

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

da=DaySearch(year,month,day);

printf("\n%d-%d-%d is %s,do you want to continue?(Y/N)",year,month,day,week[da]);

fflush(stdin);

scanf("%c",ch);

if(ch=='N'||ch=='n')

break;

}

break;

case 2:

while(1)

{

printf("\nPlease input the year which needs searched?(XXXX)");

scanf("%d",year);

if(IsLeapYear(year))

printf("\n%d is Leap year,do you want to continue?(Y/N)",year);

else

printf("\n%d is not Leap year,do you want to continue(Y/N)?",year);

fflush(stdin);

scanf("%c",ch);

if(ch=='N'||ch=='n')

break;

}

break;

case 3:

while(1)

{

printf("\nPlease input the year which needs printed(XXXX)");

scanf("%d",year);

PrintAllYear(year);

printf("\nDo you want to continue to print(Y/N)?");

fflush(stdin);

scanf("%c",ch);

if(ch=='N'||ch=='n')

break;

}

break;

case 4:

fflush(stdin);

printf("Are you sure?(Y/N)");

scanf("%c",ch);

if(ch=='Y'||ch=='y')

exit(0);

break;

default:

printf("\nError:Sorry,there is no this service now!\n");

break;

}

}

return 0;

}

用c语言编制一个万年历

大姐。。没有money的活儿。。

我可不干。

为了 一口气。。呵呵。。

模块化的思想

#includestdio.h

#includewindows.h

#includedos.h

int days[]={0,31,59,90,120,151,181,212,243,273,304,334,365};

int month[]={31,28,31,30,31,30,31,31,30,31,30,31};

char weekday[7][7]={"一","二","三","四","五","六","七"};

int week(int y,int m,int d)

{

int day=0;

day=days[m-1]+d-1;

return (y-1+(y-1)/4-(y-1)/100+(y-1)/400+day)%7;

}

void print()

{

puts("*************************万年日历***************************");

puts("1.Week");

puts("2.Month");

puts("3.Calendar");

puts("4.Exit");

printf("您选择的是:");

}

void printmonth(int y,int m)

{

int i,j,w;

w=(week(y,m,1)+1)%7;

puts(" SUN MON TUE WED THU FRI SAT");

for(i=1;i=w;i++)

printf("%5c",' ');

for(j=i;ji+month[m-1]+(m==2(y%4==0(y%100)||y%400==0));j++)

{

printf("%5d",j-i+1);

if(j%7==0)

puts("");

}

if((j-1)%7)

puts("");

}

int printweek()

{

int y,m,d;

char temp[1];

system("cls");

puts("请输入年月日, 格式如:2012 12 25");

printf("年月日为:");

scanf("%d%d%d",y,m,d);

printf("\n%4.4d年%2.2d月%2.2d日 是星期%s\n\n是否继续查询(Y/N)? ",y,m,d,weekday[week(y,m,d)]);

scanf("%s",temp);

while(1){

if(temp[0]=='N' || temp[0]=='n')

return 0;

else if(temp[0]=='y' || temp[0]=='Y')

printweek();

else

puts("输入错误!请输入n/y");

scanf("%s",temp);

}

return 0;

}

int printmonth2()

{

int y,m;

char temp[1];

system("cls");

puts("请输入要打印的年份/月份,格式如:2012 12");

printf("年月为: ");

scanf("%d%d",y,m);

printf(" %4.4d年%2.2d月\n",y,m);

printmonth(y,m);

printf("是否继续查询(Y/N)?");

scanf("%s",temp);

while(1){

if(temp[0] =='N' || temp[0] =='n')

return 0;

else if(temp[0]=='Y' || temp[0]=='y')

printmonth2();

else

puts("输入错误 !请输入y/n");

scanf("%s",temp);

}

return 0;

}

int printcalender()

{

int y,i;

char temp[1];

system("cls");

puts("请输入要打印的年份,格式如:2012");

printf("年份为: ");

scanf("%d",y);

printf(" %4.4d\n",y);

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

{

printf(" %2.2d月份\n",i);

printmonth(y,i);

}

printf("是否继续查询(Y/N)?");

scanf("%s",temp);

while(1)

{

if(temp[0]=='N' || temp[0]=='n')

return 0;

else if(temp[0]=='Y' || temp[0]=='y')

printcalender();

else

puts("输入错误!请输入y/n");

scanf("%s",temp);

}

return 0;

}

int exit1()

{

char temp[1];

system("cls");

printf("是否要真的退出(Y/N)? ");

scanf("%s",temp);

while(1){

if(temp[0]=='y' || temp[0]=='Y')

puts("bye_bye");

exit(0);

else if(temp[0]=='n' || temp[0]=='N')

return 0;

else

puts("输入错误!请输入y/n");

scanf("%s",temp);

}

return 0;

}

int main(void)

{

int temp;

print();

scanf("%d",temp);

while(1)

{

if(temp==4)

exit1();

switch(temp)

{

case 1:

printweek();

break;

case 2:

printmonth2();

break;

case 3:

printcalender();

break;

default:

printf("请入输入正确的选项\n");

system("pause");

break;

}

system("cls");

print();

scanf("%d",temp);

}

return 0;

}

C语言课程设计——万年历

#includestdio.h

#includebios.h

struct data

{

int year1;

int specialmonth;

int month1[13];

};

struct day{

int year2;

int month2;

int day2;

};

int dis_day1(struct day *op,int *p)

{

int n=0,x;

n+=(op-year2-1980)*365;

for(x=1980;xop-year2;x++)

if((x%4==0x%100!=0)||(x%100==0x%400==0))n+=1;

for(x=1;x(op-month2);x++)

n+=*(p+x-1);

x=op-year2;

if(((x%4==0x%100!=0)||(x%100==0x%400==0))op-month22)n+=1;

n+=(op-day2-1);

return n;

}

int dis_day2(struct day *op,struct data *p)

{

int n=0,maxmonth,i,x;

for(x=1980;xop-year2;x++)

{ if((p+x-1979)-specialmonth==0)maxmonth=12;

else maxmonth=13;

for(i=0;imaxmonth;i++)

if((p+x-1979)-month1[i]==0)n+=29;

else n+=30;

}

if((p+op-year2-1979)-specialmonth!=0)

if((p+op-year2-1979)-specialmonthop-month2)op-month2++;

for(i=1;iop-month2;i++)

{

if((p+op-year2-1979)-month1[i-1]==0)n+=29;

else n+=30;}

n+=(op-day2-1);

n+=46;

return n;

}

void work_out2(struct day *re,struct data *p,int n)

{

int n1=0,maxday,maxmonth,month,day,judge=0;

re-year2=1979;re-month2=11;re-day2=14;

while(1)

{

if(judge==1)break;

if(p-specialmonth==0)maxmonth=12;

else maxmonth=13;

if(p-year1==1979)month=12;

else month=1;

for(;month=maxmonth;month++)

{

if(p-month1[month-1]==0)maxday=29;

else maxday=30;

if((p-year1==1979)(maxday==30))day=14;

else day=1;

for(;day=maxday;day++)

{

if(n1==n){if(maxmonth==13monthp-specialmonth)month-=1;

re-year2=p-year1;re-month2=month;re-day2=day;judge=1;break;}

else n1+=1;

}

if(judge==1)break;}

p++;

}

}

void work_out1(struct day *re,int n,int *p)

{

int year=1980,n1=0,month,day,maxday,judge=0;

re-year2=1980;re-month2=1;re-day2=1;

while(1)

{

*(p+1)=28;

if(judge==1)break;

if((year%4==0year%100!=0)||(year%100==0year%400==0))*(p+1)=29;

for(month=1;month=12;month++)

{

maxday=*(p+month-1);

for(day=1;day=maxday;day++)

{

if(n1==n){re-year2=year;re-month2=month;re-day2=day;judge=1;break;}

else n1++;

}

if(judge==1)break;}

year++;

}

}

main()

{

int n,c;

int sun[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int *p1=sun;

struct day ob,re; struct data *p2;

struct data year[37]={

{1979,6, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 },

{1980,0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0 },

{1981,0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0 },

{1982,4, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1 },

{1983,0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0 },

{1984,10,1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1 },

{1985,0, 0, 1, 1, 0, 1, 0, 1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0, 0, 1, 0, 1, 1, 1, 0, 1, 0 },

{2008,0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0 },

{2009,5, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1 },

{2010,0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 },

{2011,0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0 },

{2012,4, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },

{2013,0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 },

{2014,9, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1 },

{2015,0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0 }

};

p2=year;

printf(" WARNING \n");

printf(" you should take care of it :\n");

printf(" the limted range:\n");

printf(" lunar calendar: 1980.1.1----2015.11.12\n");

printf(" soalr calendar: 1980.1.1-----2015.12.31\n");

while(1)

{ printf(" please choose one way a/b?\n");

printf(" a: soalr calendar----lunar calendar\n");

printf(" b: lunar calendar----soalr calendar\n");

do{c=getchar();}while(c!='a'c!='b');

do{

printf("your must pay attention to the form\n");

printf("pleae input your date:\n");

scanf("%d.%d.%d",ob.year2,ob.month2,ob.day2);

}while(ob.year21980||ob.year2=2016||ob.month21||

ob.month212||ob.day21||ob.day231);

switch©

{

case 'a':

n=dis_day1(ob, p1);printf("%d\n",n);

work_out2(re,p2,n);

printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);break;

case 'b':

n=dis_day2(ob,p2);printf("%d\n",n);

work_out1(re,n,p1);

printf(" the result is %d.%d.%d\n",re.year2,re.month2,re.day2);

if(ob.month2==(p2+ob.year2-1979)-specialmonth)

{ if((ob.day2!=30)||((p2+ob.year2-1979)-month1[ob.month2]==1))

{ n+=((p2+ob.year2-1979)-month1[ob.month2-1]+29);

work_out1(re,n,p1);

printf("there is a other result\n:\t%d.%d.%d\n",re.year2,re.month2,re.day2);

}

}

break;

defluat: break;

}

printf("if you want to try again,y/n?\n");

do{c=bioskey(0);}while(c!=0x316ec!=0x1579);if(c==0x316e)break;

}

}

用C语言怎么编写万年历

1、首先下载安装Notepad++,这是一款免费的且能够编辑C语言的软件。

2、然后下载安装tdm-gcc,这是为了给电脑配置环境变量,以便能够编译C语言的。

3、在安装完以上两款软件后,还要配置一下环境变量。

4、然后开始编辑C语言万年历,首先要判断一个年份是闰年还是平年,用一个子程序来做:

5、然后就开始写主程序:首先用scanf得到一个年份,在判断这个年份是平年还是闰年后用printf在CMD中打出来。

6、在编写完成后,在Notepad++界面下按下F5,在输入框中输入:

cmd /k gcc -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" CLS "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" PAUSE EXIT

7、最后点击运行,会弹出CMD,在里面输入年份后回车:例如输入2017,然后回车,就会生成2017年的万年历了!

c语言设计万年历

/*不过除了没有查询某年某月某日是这一年的第几天。。和判断这一年的生肖外,都能满足你的要求。

加点金币帮你完善点!*/

#includestdio.h

int

Swiss(int

Years)

//判断是否是闰年

{

if(!(Years%100))

{

Years=Years/100;

}

if(Years%4)

{

return

0;

}

else

{

return

1;

}

}

int

Number(int

Yearsa,int

Yearsb)

//已知两个年份,求出两个年份之间闰年的个数

{

int

i=Yearsa+1;

int

mou=0;

do{

if(Swiss(i))

{

mou++;

}

i++;

}while(iYearsb);

return

mou;

}

int

Mvalue(int

Years,int

Month,int

Day)

//已知年月日,求出某年某月某日是星期几

{

int

M[12]={0,3,3,6,1,4,6,2,5,0,3,5};

//月值

int

N=6;

//年值初始化

int

a;

if(Years2006)

//求年值,年值以2006年为基数

{

N=6-((2006-Years)%7)-Number(Years,2006);

if(Swiss(Years))

{

if(Month3)

{

N--;

}

}

}

else

if(Years2006)

{

N=((Years-2006)%7)-1+Number(2006,Years);

if(Swiss(Years))

{

if(Month2)

{

N++;

}

}

}

a=(Day+M[Month-1]+N)%7;

//某年某月某日是星期几=(日值+月值+年值)%7

return

a;

}

int

Amonth(int

Month)

//已知月,求出这个月是大月还是小月

{

switch(Month)

{

case

1:

case

3:

case

5:

case

7:

case

8:

case

10:

//1,3,5,7,8,10,12是大月,没月31天

case

12:return

1;

case

4:

case

6:

case

9:

case

11:return

0;

//4,6,9,11是小月,每月30天

case

2:return

2;

//二月份

}

return

-1;

}

void

main

()

{

int

Dtable[7][7];

int

i,j;

int

Years=9999;

int

Month=12;

int

Day=1;

int

b;

for(i=0;i7;i++)

//初始化数组

{

Dtable[0][i]=i;

}

for(i=1;i7;i++)

{

for(j=0;j7;j++)

{

Dtable[i][j]=0;

}

}

i=Mvalue(Years,Month,Day);

switch(Amonth(Month))

{

case

0:b=30;break;

case

1:b=31;break;

case

2:if(Swiss(Years))b=29;else

b=28;break;

//闰年2月29天,平年二月28天

default:b=-1;break;

}

for(;i7;i++)

{

Dtable[1][i]=Day++;

}

for(i=2;i7;i++)

{

for(j=0;j7;j++)

//建造日历表

{

if(Day=b)

{

Dtable[i][j]=Day++;

}

else

{

continue;

}

}

}

printf("%d:%d\n",Years,Month);

for(i=0;i7;i++)

//输出日历表

{

for(j=0;j7;j++)

{

printf("%3d",Dtable[i][j]);

}

printf("\n");

}

getch();

//完毕!

}