日历显示源代码(c语言日历源代码)
admin 发布:2022-12-19 19:17 109
今天给各位分享日历显示源代码的知识,其中也会对c语言日历源代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、求C语言编日历源代码的详细说明
- 2、C语言编写 年历显示程序
- 3、日历代码
- 4、ASP+JS日历源代码
求C语言编日历源代码的详细说明
/*
稍微改了下对齐格式,加了注释
*/
/*
1、闰年的算法:
如果某年能被4整除但不能被100整除,
或者能被400整除,
则该年是闰年.
用表达式表示就是
(year
%4
==
year%100
!=
0)
||
(year%400
==
0)
2、计算某一天是星期几:
已知1900年的1月1号为星期一,
然后就可以用某一天和1900年的1月1号相差的天数对7取余来求星期,
本题是用的公元1年的1月1号作为基准
*/
#include
stdio.h
#includeconio.h
#includestdlib.h
int
IsLeapYear(int);
//函数定义
void
main()
{
int
i;
int
day;
int
year;
int
temp;
int
temp_i;
long
int
Year_days
=
0;
int
Year_Start
=
1;
int
Per_Year_Days;
int
month_day[]={31,28,31,30,31,30,31,31,30,31,30,31,29};
printf("Please
enter
the
year:
");
scanf("%d",year);
//输入年份
while(Year_Start
year)
//从公元1年开始执行while循环,
该年的一月一号为星期一
{
if(
IsLeapYear(
Year_Start
)
)
Per_Year_Days
=
366;
//如果是闰年,
则一年有366天
else
Per_Year_Days
=
365;
//如果不是闰年,
则一年有365天
Year_days
=
Year_days
+
Per_Year_Days;
//Year_days为从公元1年到输入年份的前一年的天数的总和
Year_Start++;
}
for(
temp
=
1;
temp
=12;
temp++
)
//temp从1到12,
对应一年内12个月
{
switch(
temp
)
//用switch语句将temp和12个月对应起来
{
case
1:
printf("
January(%d)\n",year);
//一月
break;
case
2:
printf("
February(%d)\n",year);
//二月
break;
case
3:
printf("
March(%d)\n",year);
//三月
break;
case
4:
printf("
April(%d)\n",year);
//四月
break;
case
5:
printf("
May(%d)\n",year);
//五月
break;
case
6:
printf("
June(%d)\n",year);
//六月
break;
case
7:
printf("
July(%d)\n",year);
//七月
break;
case
8:
printf("
August(%d)\n",year);
//八月
break;
case
9:
printf("
September(%d)\n",year);
//九月
break;
case
10:
printf("
October(%d)\n",year);
//十月
break;
case
11:
printf("
November(%d)\n",year);
//十一月
break;
case
12:
printf("
December(%d)\n",year);
//十二月
break;
}
i
=
Year_days
%
7;
//每个星期有7天,
故用每年的天数对7取余
printf("Mon\tTue\tWed\tThu\tFri\tSat\tSun\n");
if(
i
!=
)
//如果余数不为零
for(
temp_i
=
0;
temp_i
i;
temp_i++)
printf("\t");
//则打印空格(这里用\t代替空格,
更加美观),
空格数为i
day
=
1;
//初始化day为1,
为下面的while循环做准备
if(
IsLeapYear(year)
temp
==
2)
//如果输入的年份是闰年,
并且月份为2
while(
day
=
month_day[12]
)
//day为一循环变量,
取值为1-365(闰年的话为1-366)
{
if(
day
1
)
//如果天数大于一
if(
Year_days
%
7
==
)
//如果是星期日,
则换行
printf("\n");
if(
day
=
10
)
printf("%d\t",day);
//打印天数+空格
else
printf("%d\t",day);
Year_days++;
day++;
}
else
//如果不满足"输入的年份是闰年,
并且月份为2"
while
(day
=
month_day[temp-1])
{
if(
day
1
)
if(
Year_days
%
7
==
)
printf("\n");
if(
day
=10
)
printf("%d\t",day);
else
printf("%d\t",day);
Year_days++;
day++;
}
printf("\n");
if(
getch()
==
'q'
)
//如果输入为q,
则退出程序
exit(0);
}
getch();
//每按一次键,
打印一个月份
}
int
IsLeapYear(
int
year
)
{
//判断是否是闰年,
是则返回1,
否则返回0
if
((year
%4
==
0)
(year
%
100
!=
0)
||
(year
%
400
==
0)
)
return
1;
else
return
0;
}
C语言编写 年历显示程序
此题不是很难,我会前三个
关键是算那一年的第一天是周几
给你个基本算法,一年是365天,闰年366天
364是7的倍数,这样一年多出一天,中间多少个闰年,在加上相应的天数即可
400年多出来的天数是400+97=497也是7的倍数,那么400年一轮回,这样就算400年以内的即可
一个子函数,返回这一年的第一天是周几,很好做
int ye(int year)
{
int y=year%400;
int day=y;
int i;
for(i=0;iy;i++)
if(闰年判断)
day++;
return day%7;
}
做一个月份天数的全局数组
int mo[12]={31,28,31,30,31,30,31,31,30,31,30,31};
需要时用一个if判断闰年改变m0[1]的值是28还是29
打印子函数,有一个小技巧,就是每个月前面的空缺部分,这个1月份是ye子函数的返回值,后面的你看和前面月份是不是重合啊,吧这个记录下来在下一月份用即可
1 2
3 4
这样月份排列更好打印一些,你的那个截图有点麻烦
int pr(int year)
{
int k=ye(year);
int i,j,;
if(闰年判断)
mo[1]=29;
else
mo[1]=28;
for(i=0;i12;i++)
{
printf("周几英文的打印");
for(j=0;jk;j++)
printf("一般是四个空格,就是月份前面空缺的打印");
for(j=1;j=mo[i];j++)
{
printf("%4d",j);
k++;
if((k+j)%7==0)
printf("\n");
}
k%=7;
if(k!=0)
printf("\n");
}
}
如果像你那样,感觉需要赋值一个大一点的数组,在吧数组打印出来更好,呵呵
日历代码
万年历代码:
iframe
src=""
width="509"
height=433
marginwidth="0"
marginheight="0"
hspace="0"
vspace="0"
frameborder="0"
scrolling="no"/iframe
老黄历的源代码:
IFRAME
style="BORDER-RIGHT:
#000000
1px
dotted;
BORDER-TOP:
#000000
1px
dotted;
BORDER-LEFT:
#000000
1px
dotted;
BORDER-BOTTOM:
#000000
1px
dotted"
border=0
name=nongli
marginHeight=0
src=""
frameBorder=no
width=149
scrolling=no
height=140/IFRAME
最新日历代码(包括日历、星期、现在时间)
IFRAME
border=0
name=www1.xise.cn
align=center
marginWidth=0
marginHeight=0
src=""
frameBorder=0
width=146
scrolling=no
height=183/IFRAME
代码一:IFRAME
style="BORDER-RIGHT:
#000000
1px
dotted;
BORDER-TOP:
#000000
1px
dotted;
BORDER-LEFT:
#000000
1px
dotted;
BORDER-BOTTOM:
#000000
1px
dotted"
border=0
name=nongli
marginHeight=0
src=""
frameBorder=no
width=149
scrolling=no
height=140/IFRAME
代码二:iframe
name="jiro23"
src=""
width="500"
height="500"/iframe
代码三:iframe
scrolling=no
height=170
width=165
frameborder=0
marginHeight=0
marginWidth=0
src=;/iframe
具体步骤是:复制代码---管理博客-----新增空白面板-----钩选显示源代码(出现钩号,同时文档里出现DIV的字样)----粘贴代码----钩选显示源代码(钩号消失)-----保存新增面板----定制个人首页----选取新增个人面板----保存设置
ASP+JS日历源代码
直接保存成 asp文件 运行就可以
html
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
link href="" rel="schema.DC" /
title日历/title
/head
body bgcolor="#FFFFFF"
%
' 要调用的函数声明
'根据年份及月份得到每月的总天数
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
'得到一个月开始的日期.
Function GetWeekdayMonthStartsOn(dAnyDayInTheMonth)
Dim dTemp
dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function
'得到当前一个月的上一个月.
Function SubtractOneMonth(dDate)
SubtractOneMonth = DateAdd("m", -1, dDate)
End Function
'得到当前一个月的下一个月.
Function AddOneMonth(dDate)
AddOneMonth = DateAdd("m", 1, dDate)
End Function
' 函数声明结束
Dim dDate ' 日历显示的日期
Dim iDOW ' 每一月开始的日期
Dim iCurrent ' 当前日期
Dim iPosition ' 表格中的当前位置
' 得到选择的日期并检查日期的合法性
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("month") "-" Request.QueryString("day") "-" Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("month") "-" Request.QueryString("day") "-" Request.QueryString("year"))
Else
dDate = Date()
If Len(Request.QueryString("month")) 0 Or Len(Request.QueryString("day")) 0 Or Len(Request.QueryString("year")) 0 Or Len(Request.QueryString("date")) 0 Then
Response.Write "您所选择的日期格式不正确,系统会使用当前日期.BRBR"
End If
End If
End If
'得到日期后我们先得到这个月的天数及这个月的起始日期.
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(dDate)
%
table width="180" height="100%" border="0" cellpadding="0" cellspacing="0"
tr
tdtable width="150" border="0" align="center" cellpadding="0" cellspacing="0"
tr
td height="5" /td
/tr
/table
table width="180" border="0" align="center" cellpadding="0" cellspacing="0"
tr
td align="center" colspan="7"table border="0" cellpadding="0" cellspacing="0"width="100%"
tr
td height="22" align="right"a href="rl.asp?date=%= SubtractOneMonth(dDate) %"img src="../images/dot_left.gif" width="15" height="14" border="0" //a/td
td align="center"font color="999999"b%= MonthName(Month(dDate)) " " Year(dDate) %/b/font/td
tda href="rl.asp?date=%= AddOneMonth(dDate) %"img src="../images/dot_right.gif" width="15" height="14" border="0" //a/td
/tr
/table/td
/tr
tr
td width="25" height="22" align="center"font
color="d08c00"b日/b/font /td
td width="25" align="center"bfont color="999999"一/font/b /td
td width="25" align="center"bfont color="999999"二/font/b /td
td width="25" align="center"bfont color="999999"三/font/b /td
td width="25" align="center"bfont color="999999"四/font/b /td
td width="25" align="center"bfont color="999999"五/font/b /td
td width="25" align="center"bfont color="d08c00"六/font/b /td
/tr
%
' 如果这个月的起始日期不是周日的话就加空的单元.
If iDOW 1 Then
Response.Write vbTab "TR" vbCrLf
iPosition = 1
Do While iPosition iDOW
Response.Write vbTab vbTab "TD /TD" vbCrLf
iPosition = iPosition + 1
Loop
End If
' 绘制这个月的日历
iCurrent = 1
iPosition = iDOW
Do While iCurrent = iDIM
' 如果是一行的开头就使用 TR 标记
If iPosition = 1 Then
Response.Write vbTab "TR" vbCrLf
End If
' 如果这一天是我们选择的日期就高亮度显示该日期.
If iCurrent = Day(dDate) Then
Response.Write vbTab vbTab "TD BGCOLOR=#eeeeee height=18 align=centerB" iCurrent "/B/TD" vbCrLf
Else
Response.Write vbTab vbTab "TD height=18 align=centerA HREF=""./rl.asp?date=" Month(dDate) "-" iCurrent "-" Year(dDate) """" iCurrent "/A/TD" vbCrLf
End If
' 如果满一周的话表格就另起一行
If iPosition = 7 Then
Response.Write vbTab "/TR" vbCrLf
iPosition = 0
End If
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
' 如果一个月不是以周六结束则加上相应的空单元.
If iPosition 1 Then
Do While iPosition = 7
Response.Write vbTab vbTab "TD /TD" vbCrLf
iPosition = iPosition + 1
Loop
Response.Write vbTab "/TR" vbCrLf
End If
%
/table
table width="150" border="0" align="center" cellpadding="0" cellspacing="0"
tr
td height="5" /td
/tr
/table/td
/tr
/table
关于日历显示源代码和c语言日历源代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:网站下载代码(网站代码软件)
- 下一篇:js代码位置(js代码在线运行)
相关推荐
- 04-29恐龙快打源代码(java恐龙快打)[20240429更新]
- 04-29微信小程序源代码下载(微信小程序代码下载)[20240429更新]
- 04-29web课程设计源代码(网页设计与制作课程代码)[20240429更新]
- 04-29asp.net个人主页源代码(ASPNET网站开发)[20240429更新]
- 04-29thinkphpapp源代码(thinkphp源码安装教程)[20240429更新]
- 04-29包含wget源代码分析的词条[20240429更新]
- 04-29jsp收费系统源代码的简单介绍[20240429更新]
- 04-29在线网页源代码(在线网页源代码查看器)[20240429更新]
- 04-29手机浏览器显示源代码(手机浏览器怎么看源代码)[20240429更新]
- 04-28安卓小游戏代码项目下载(java简单手机小游戏源代码)[20240428更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接