c语言万年历设计
❶ 设计一个万年历c语言
|#include<stdio.h>
int getDays(int year,int month,int day);
int isLeapYear(int year);
int getMonthDays(int year,int month);
void main()
{
int year,month,day;
int i,days=0,weekday,monthdays;
int calendar[42]={0};
char *p[7]={"SUN","MON","TUE","WES","THU","FRI","SAT"};
scanf("%d-%d-%d",&year,&month,&day);
for(i=1980;i<year;i++)
{
if(isLeapYear(i))
days+=366;
else days+=365;
}
days+=getDays(year,month,1);
weekday=(days+1)%7;
//printf("%d",weekday);
monthdays=getMonthDays(year,month);
for(i=0;i<monthdays;i++)
{
calendar[weekday+i]=i+1;
}
for(i=0;i<7;i++)
{
printf("%s ",p[i]);
}
printf("\n");
for(i=0;i<42;i++)
{
if(calendar[i]!=0)
{
if(calendar[i]==day)
printf("[%d]",day);
else printf("%3d ",calendar[i]);
}
else printf(" ");
if((i+1)%7==0)
printf("\n");
}
}
int getMonthDays(int year,int month)
{
int days;
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:days=31;break;
case 4:case 6:case 9:case 11:days=30;break;
case 2:if(isLeapYear(year))days=29;
else days=28;
}
return days;
}
int getDays(int year,int month,int day)
{
int days=0;
switch(month)
{
case 12:days+=30;
case 11:days+=31;
case 10:days+=30;
case 9 :days+=31;
case 8 :days+=31;
case 7 :days+=30;
case 6 :days+=31;
case 5 :days+=30;
case 4 :days+=31;
case 3 :if(isLeapYear(year))days+=29;
else days+=28;
case 2 :days+=31;
}
days+=day;
return days;
}
int isLeapYear(int year)
{
if((year%400==0)||((year%4==0)&&(year%100!=0)))
{
return 1;
}
else
{
return 0;
}
}
❷ 请使用C语言设计一个万年历和记事本,急!
我来回答了,把分给我吧!
❸ C语言编写万年历实验设计
网上找的部分带我,我又修改了一下,现在基本满足lz的要求。
手头没有Wintc用vc测的,不过没用到什么vc特有的东西,应该可以的。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void DayOfWeek()
{
int rtnDay;
int y,m,d;
char ch;
while (1)
{
printf("请输入年月日(xxxx,xx,xx): ");
scanf("%d,%d,%d", &y, &m, &d);
fflush(stdin);
rtnDay = (3*y-(7*(y+(m+9)/12))/4+(23*m)/9+d+17-((y+(m<3?-1:0))/100+1)*3/4) % 7;
printf("%04d年%02d月%02d日 是 星期%d\n", y, m, d, rtnDay?rtnDay:7);
printf("继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetMonth(int D, int md, int n)
{
int N ,m,d,y,c,Wd;
int i,maxday,i1;
if(md>=13||md<=0)
printf("HAVE WRONG!");
else
{
for(i1=0;;md++,i1++)
{
if(md==0)
{
md=12;
D-=1;
}
else
if(md==13)
{
md=1;
D+=1;
}
m=md;
printf("\n============%d,%2d============\n",D,md);
if(0<m&&m<=12)
{
switch(m)
{
case 1:maxday=31;break;
case 2:if(D%4==0&&D%100!=0||D%400==0)
maxday=29;
else
maxday=28;
break;
case 3:maxday=31;break;
case 4:maxday=30;break;
case 5:maxday=31;break;
case 6:maxday=30;break;
case 7:maxday=31;break;
case 8:maxday=31;break;
case 9:maxday=30;break;
case 10:maxday=31;break;
case 11:maxday=30;break;
case 12:maxday=31;break;
default:printf("HAVE WRONG");
}
if(0<m&&m<=2)
{
N=D-1;
m=m+10;
}
else
{
N=D;
m=m-2;
}
c=N/100;
y=N%100;
Wd=((1+(13*m-1)/5+y+y/4+c/4-2*c)%7+7)%7;
printf(" SUN MOU TUE WED TUR FRI SAT\n");
for(i=0;i<Wd;i++)
printf("%4c",' ');
for(d=1;d<=maxday;d++)
{
printf("%4d",d);
Wd=(Wd+1)%7;
if(Wd==0)
printf("\n");
}
}
else
printf("HAVE WRONG!");
if(i1==n)
break;
}
}
}
void MonthOfYear()
{
char ch;
int y, m;
while (1)
{
printf("请输入年月(xxxx,xx): ");
scanf("%d,%d", &y, &m);
fflush(stdin);
GetMonth(y, m, 0);
printf("\n继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
void GetYear()
{
char ch;
int y;
while (1)
{
printf("请输入年: ");
scanf("%d", &y);
fflush(stdin);
GetMonth(y, 1, 11);
printf("\n继续查询(y/n)");
ch = getchar();
if(ch != 'y' && ch != 'Y')
break;
}
}
int main()
{
char ch;
while(1)
{
system("cls");
printf("1.查询星期\n");
printf("2.查询月份\n");
printf("3.显示一年\n");
printf("4.退出程序\n");
ch = getchar();
fflush(stdin);
switch(ch)
{
case '1':
DayOfWeek();
break;
case '2':
MonthOfYear();
break;
case '3':
GetYear();
break;
case '4':
printf("是否退出(y/n)");
ch = getchar();
fflush(stdin);
if(ch == 'y' || ch == 'Y')
exit(0);
break;
}
}
}
❹ 用C语言编写万年历,急!
已经编译运行确认过。
#INCLUDE <STDIO.H>
#INCLUDE <STDLIB.H>
INT LEAP(INT); /*判断是否为闰年*/
INT MD(INT M,INT Y); /*返回本月的天数*/
VOID PRTWEEK(VOID); /*输出表头*/
INT FW(INT M,INT Y); /*返回本月一号是星期几*/
VOID PRTMONTH(INT M); /*输出月份表头*/
INT MAIN(VOID)
{
INT Y,M,I,TEST,WEEK;
PRINTF("PLEASE IMPORT YEAR OF YOU WANT TO SELECT : ");
SCANF("%D",&Y);
FOR (M=1; M<=12; M++) {
TEST=1;
PRTMONTH(M);
PRTWEEK();
WEEK=FW(M,Y);
IF (WEEK!=6)
FOR (I=0; I<=WEEK; I++) {
PUTCHAR('\T');
TEST++;
}
FOR (I=1; I<=MD(M,Y); I++,TEST++) {
PRINTF("%D\T",I);
IF (TEST%7==0) {
PUTCHAR('\N');
}
}
PUTCHAR('\N');
SYSTEM("PAUSE");//暂停,以便观察输出
}
RETURN 0;
}
INT LEAP(INT Y)
{
RETURN (Y%4==0&&Y%100||Y%400==0)?1:0;
}
INT MD(INT M,INT Y)
{
INT D;
SWITCH (M) {
CASE 1:
CASE 3:
CASE 5:
CASE 7:
CASE 8:
CASE 10:
CASE 12:D=31;BREAK;
CASE 4:
CASE 6:
CASE 9:
CASE 11:D=30;BREAK;
CASE 2:D=LEAP(Y)?29:28;BREAK;
}
RETURN D;
}
VOID PRTWEEK(VOID)
{
PRINTF("%S\T%S\T%S\T%S\T%S\T%S\T%S\T\N","SUN","MON","TUE","WED","THUR","FRI","SAT");
}
INT FW(INT M,INT Y)
{
INT F;
IF (M<3) {
M+=12;
Y--;
}
F=(1+2*M+3*(M+1)/5+Y+Y/4-Y/100+Y/400)%7;
RETURN F;
}
VOID PRTMONTH(INT M)
{
SWITCH (M) {
DEFAULT:
CASE 1:PUTS("===JANUARY===");BREAK;
CASE 2:PUTS("===FEBRUARY===");BREAK;
CASE 3:PUTS("===MARCH===");BREAK;
CASE 4:PUTS("===APRIL===");BREAK;
CASE 5:PUTS("===MAY===");BREAK;
CASE 6:PUTS("===JUNE===");BREAK;
CASE 7:PUTS("===JULY===");BREAK;
CASE 8:PUTS("===AUGUST===");BREAK;
CASE 9:PUTS("===SEPTEMBER===");BREAK;
CASE 10:PUTS("===OCTOBER===");BREAK;
CASE 11:PUTS("===NOVEMBER===");BREAK;
CASE 12:PUTS("===DECEMBER===");BREAK;
}
❺ c语言程序设计 万年历报告书
||#include <stdio.h>
void main()
{
int year,month,day,days,sum,i,n=0,a;
char c;
redo: printf("请输入年/月/日(例如:2010/1/1):\n");
scanf("%d/%d/%d",&year,&month,&day);
if(month==1&&(day>=32||day<=0))
{
printf("输入有误!1月只能有31天!\n");
goto redo;
}
if(month==2)
{
if((year%400==0)||(year%4==0&&year%100!=0))
{
if(day>=30||day<=0)
{
printf("输入有误!%d年是闰年,二月只能有29天!\n",year);
goto redo;
}
}
else if(day>=29||day<=0)
{
printf("输入有误!%d年是平年,二月只能有28天!\n",year);
goto redo;
}
}
if(month==3&&(day>=32||day<=0))
{
printf("输入有误!3月只能有31天!\n");
goto redo;
}
if(month==4&&(day>=31||day<=0))
{
printf("输入有误!4月只能有30天!\n");
goto redo;
}
if(month==5&&(day>=32||day<=0))
{
printf("输入有误!5月只能有31天!\n");
goto redo;
}
if(month==6&&(day>=31||day<=0))
{
printf("输入有误!6月只能有30天!\n");
goto redo;
}
if(month==7&&(day>=32||day<=0))
{
printf("输入有误!7月只能有31天!\n");
goto redo;
}
if(month==8&&(day>=32||day<=0))
{
printf("输入有误!8月只能有31天!\n");
goto redo;
}
if(month==9&&(day>=31||day<=0))
{
printf("输入有误!9月只能有30天!\n");
goto redo;
}
if(month==10&&(day>=32||day<=0))
{
printf("输入有误!10月只能有31天!\n");
goto redo;
}
if(month==11&&(day>=31||day<=0))
{
printf("输入有误!11月只能有30天!\n");
goto redo;
}
if(month==12&&(day>=32||day<=0))
{
printf("输入有误!12月只能有31天!\n");
goto redo;
}
if(month>=1&&month<=12)
{
if(year%400==0||(year%4==0&&year%100!=0))
printf("%d年是闰年。\n",year);
else printf("%d年是平年。\n",year);
}
if(year>=1901) goto loop1;
else goto loop2;
loop1: for(i=1901;i<year;i++)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(year-1901-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
}
a=sum+day+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a++;
if(a%7==1) printf("%d年%d月%d日是星期二。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
goto label;
loop2: for(i=1900;i>year;i--)
{
if(i%400==0||(i%4==0&&i%100!=0))
n++;
}
days=(1900-year-n)*365+n*366;
switch(month)
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=58;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("一年内只能有12个月!请重新输入!\n");goto redo;
}
if(year%400==0||(year%4==0&&year%100!=0))
a=366-(day+sum)+days;
else a=365-(day+sum)+days;
if((year%400==0||(year%4==0&&year%100!=0))&&(month>=3))
a--;
if(a%7==0) printf("%d年%d月%d日是星期一。\n",year,month,day);
if(a%7==1) printf("%d年%d月%d日是星期天。\n",year,month,day);
if(a%7==2) printf("%d年%d月%d日是星期六。\n",year,month,day);
if(a%7==3) printf("%d年%d月%d日是星期五。\n",year,month,day);
if(a%7==4) printf("%d年%d月%d日是星期四。\n",year,month,day);
if(a%7==5) printf("%d年%d月%d日是星期三。\n",year,month,day);
if(a%7==6) printf("%d年%d月%d日是星期二。\n",year,month,day);
label: printf("Do you want to continue?Y/N:");
getchar();
c=getchar();
if(c=='Y'||c=='y')
{
n=0;
goto redo;
}
}
❻ 求大神!C语言编写《万年历的设计》。。。
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<ctime>
usingnamespacestd;
intmain()
{
tm*year1;
tm*month1;
time_tt;
t=time(0);
year1=localtime(&t);
month1=localtime(&t);
intf;//元月一抄日是星期几
intoffset;//元月一日是星期几
intday=1;//第一天
intyear;
intmonth;
intd;//一月一日到这个月天数
intg;//计算是周几
......
要是满意,请点赞,发源码
❼ C语言课程设计-万年历
1.系统封面设计
内容:题目名称(中英文)、进入(中英文)、作者:***、时间:****-**-**
2.输入界面
内容:(1)密码口令输入及容错(3次)
(2)年份的输入及容错(3次)
3.日历计算设计
(1)求某月某日实行奇迹的函数(邱每月一号的星期数)。算法:(y-1)+(y-1)/4-(y-1)/100+(y-1)/400+c 得出S (y为年份,c为某月某日是这一年的第几天,S为总的天数)
(2)邱某月某日至这一年第几天的函数(求c) 闰年的算法: y/400==0 ?或y/400==0&&y/100!=0
根据(1)(2)求出每个月的日期
4、日历格式显示设计
要求:每屏显示4个月。
-------------------------------
❽ C语言程序设计万年历
#include <stdio.h>
int leap (int year)
{if(year%4==0&&year%100!=0||%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; //判断二月是29天还是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++;
}
}
}
printf("\n");
}
❾ C语言程序设计~~~万年历
#include<stdio.h>
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;
}
void main()
{
int i,j=1,k=1,a,b,month,year;
printf("input month and year:");
scanf("%d%d",&month,&year);
b=days_month(month,year);
a=firstday (month,year);
printf("\n******************************\n");
printf(" 公元%d年%2d月",year,month); printf("\n******************************\n");
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++;
}
}
}
printf("\n");
}
❿ c语言设计万年历
看看没人帮你,我来帮你吧,以下是我新写的,用了我自己原创的算法,完全不同于网上的程序,等于说是专门为你量身定制的。奉上程序:
#include<stdio.h>
#include<windows.h>
char*NameOfMonth[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char*WeekDay[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
intIsLeapYear(intyear)
{
if(year%4==0&&year%100!=0||year%400==0)
{
return1;//闰年返回1
}else
{
return0;//平年返回0
}
}
intDateCheck(intuYear,intuMonth,intuDay)//合法返回true,非法或超出范围返回false
{
if(uYear<1901||uYear>9999||uMonth<1||uMonth>12||uDay<1||uDay>31)
{
return0;
}
if(uMonth==4||uMonth==6||uMonth==9||uMonth==11)
{
if(uDay>30)
{
return0;
}
}elseif(uMonth==2)
{
if(IsLeapYear(uYear))
{
if(uDay>29)
{
return0;
}
}else
{
if(uDay>28)
{
return0;
}
}
}
return1;
}
intGetDays(intyear,intmonth,intday)
{
intsum=0;
if(DateCheck(year,month,day)==0)
{
return-1;//日期有误
}
if(year>=1901)
{
intX=(int)(year/100);//世纪数
intY=X-(int)(X/4);//如果按4年一闰来算,Y指的是比实际上多算的天数,在下面需要减去
if(month<=2&&month>0)
{
year--;//把1月、2月视为上一年的13月、14月(纯粹为了计算需要)
month+=12;
}
sum=(int)(365.25*(year-1900))+(int)(30.6*(month+1))+day-Y-49;//以365.25(本来实际太阳年是365.2425天)来计算是为了计算按4年一闰的整数年总天数,加上月份天数再加上余下天数,减掉多闰天数,再减掉一个偏差值(多加的)
//月份以30.6天的平均值计算。最后减去的49,是多加的一个月以及其余相差天数的和,可得到1900年1月1日的积日为0
}
returnsum;//返回距离1900年1月1日的总天数(积日)
}
intGetDayOfMonth(intmonth,intyear)
{
inttmp_days=GetDays(year,month,1);//本月积日
intDayOfMonth=0;
month++;//下个月
if(month>12)
{
month=1;//遇到月份为12月的情况,月份为1,年份加1
year++;
}
DayOfMonth=GetDays(year,month,1);//下个月的积日
DayOfMonth-=tmp_days;//下月1日的总天数(距离1900年1月1日的积日)减去当前月1日的总天数
returnDayOfMonth;//返回当前月总天数
}
intShowCalendar(intyear,intmonth,intday)
{
inti,j,count;
intjiri=0;//积日
intdayofweek=0;//星期
if(DateCheck(year,month,day)==0)
{
printf("输入日期有误!
");//日期不合法或超出范围,年历从1901年开始
return0;
}
printf(" %d%s
",year,NameOfMonth[month-1]);
printf("--------------------------------------
");
printf("SunMonTueWedThuFriSat
");
printf("--------------------------------------
");
jiri=GetDays(year,month,1);//获取距离1900年1月1日的总天数
dayofweek=(1+jiri)%7;//月首星期,因为1900年1月1日星期一
count=GetDayOfMonth(month,year);
for(i=0;i<dayofweek;i++)
{
printf("");//填充前面空格
}
for(i=1,j=dayofweek;i<=count;i++,j++)
{
if(i<10)
{
printf("%d",i);
}else
{
printf("%d",i);
}
if((j+1)%7==0)
{
if(i!=count)
{
printf("
");//满7天,换行
}
}
}
printf("
--------------------------------------
");
return1;
}
intmain()
{
intyear,month,day,nChoise=0;
inttotaldays=0;
while(1)//主循环
{
printf("******************欢迎使用万年历********************
");
printf("$菜单$
");
printf("$1.闰年判断2.星期计算$
");
printf("$$
");
printf("$3.月历查询4.打印整年日历$
");
printf("$$
");
printf("****************************************************
");
printf("输入对应的序号进行相关操作:Choise>");
scanf("%d",&nChoise);
switch(nChoise)
{
case1:
printf("请输入要判断的年份:Year>");
scanf("%d",&year);
if(year<1900||year>9999)
{
printf("输入年份超出范围!");
break;
}
if(IsLeapYear(year)==1)
{
printf("%d年是闰年!
",year);
}else
{
printf("%d年不是闰年!
",year);
}
break;
case2:
printf("请输入要判断的日期:YearMonthDay>");
scanf("%d%d%d",&year,&month,&day);
totaldays=GetDays(year,month,day);
printf("%d年%d月%d日是%s
",year,month,day,WeekDay[(totaldays+1)%7]);
break;
case3:
printf("请输入要显示的月份:YearMonth>");
scanf("%d%d",&year,&month);
ShowCalendar(year,month,1);
break;
case4:
printf("请输入要判断的年份:Year>");
scanf("%d",&year);
for(month=1;month<=12;month++)
{
ShowCalendar(year,month,1);
}
break;
default:
printf("无效的菜单项!
");
break;
}
system("pause");
system("cls");
}
return0;
}