代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
在控制台打印日历
作者:
卫强
/ 发布于
2014/10/10
/
614
/*************************************** Student:赵忠印 032-25 Date: 2006.9.23 Purpose: Coursework 1 这个程序能打印一年的日历 ***************************************/ #include<stdio.h> int isLeapyear(int year)/*this function is used to calculate that if a year is a leap year*/ { if(year%4==0) { if(year%100!=0) return 1; else if(year%100==0&&year%400==0) return 1; else return 0; } else return 0; } void printCalendar(int year,int day)/*this function is used to print the calendar of a year*/ { int month; int days; int FristDayOfMonth; int LastDayOfMonth; int i; for(month=1;month<=12;month++) { printf("\n\n"); switch(month) { case 1:printf("\tJanuary %d\n",year); days=31;/*how many days in this month*/ break; case 2:printf("\tFebruary %d\n",year); days=(isLeapyear(year))? 29:28;/*this is used to calculate if there are 29 or 28 days in february*/ break; case 3:printf("\tMarch %d\n",year); days=31; break; case 4:printf("\tApril %d\n",year); days=30; break; case 5:printf("\tMay %d\n",year); days=31; break; case 6:printf("\tJune %d\n",year); days=30; break; case 7:printf("\tJuly %d\n",year); days=31; break; case 8:printf("\tAugust %d\n",year); days=31; break; case 9:printf("\tSeptember %d\n",year); days=30; break; case 10:printf("\tOctober %d\n",year); days=31; break; case 11:printf("\tNovember %d\n",year); days=30; break; case 12:printf("\tDecember %d\n",year); days=31; break; default:printf("error"); } printf(" S M T W T F S\n");/*print the days of a week*/ if(month==1)/*January*/ { FristDayOfMonth=day;/*this is used to calculate the day of week that it is the frist day of the month*/ LastDayOfMonth=(days-8+day)%7;/*this is used to calculate the day of week that it is the last day of the month*/ } else/*other months*/ { FristDayOfMonth=(LastDayOfMonth==7)?1:LastDayOfMonth+1;/*this is used to calculate the day of week that it is the frist day of the month*/ LastDayOfMonth=(days-8+FristDayOfMonth)%7;/*this is used to calculate the day of week that it is the last day of the month*/ } for(i=1;i<FristDayOfMonth*3-2;i++)/*calculate the location of the frist day of a month*/ printf(" "); for(i=1;i<=days;i++)/*print the calendar of a month*/ { printf("%3d",i); if((i-(7-FristDayOfMonth+1))%7==0) printf("\n");/* because it is Saturday*/ } } } int main() { int choose;/*what is day today*/ int year;/*which year,you'd better input a interger*/ printf("\n\n\t\tWelcome You!\n\n"); printf("please input a year\n"); scanf("%d",&year); printf("\nplease choose the day of the week that is January 1st\n"); printf("\n1:Sunday 2:Monday 3:Tuseday 4:Wednesday 5:Thrusday 6;Friday 7:Saturday\n"); printf("\nyour choose:[ ]\b\b"); scanf("%d",&choose); if(choose<1||choose>7) { printf("choose error"); return 1; } printCalendar(year,choose);/*this function will print the whole calendar of this year that it input by you*/ getchar(); getchar(); return 1;/*because my English is poor,it is difficulty to read,please excuse you,I swear I will study it well*/ }
试试其它关键字
日历
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
卫强
贡献的其它代码
(
1
)
.
在控制台打印日历
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3