C语言万年历(代码-说明).pdf
文本预览下载声明
/*本程序在 Microsoft Visual Studio 2010 旗舰版中测试通过*/
#include stdio.h
#include stdlib.h
#include time.h
#include conio.h
#define KEYUP72//宏定义键盘的键值 (↑ )
#define KEYDOWN 80//宏定义键盘的键值 (↓ )
#define KEYLEFT 75//宏定义键盘的键值 (← )
#define KEYRIGHT 77//宏定义键盘的键值 (→ )
//函数声明部分
const int isLeap(int year);
const int getMonthDays(int year,int month);
const int yearDays(int year);
void printCalendar(int year,int month);
void main(){
int year,month;
int action =0;
//获取本地当前的年份和月份
time_t timep;
struct tm *p;
time(timep);
p = localtime(timep);
year = p-tm_year+1900;//获取本地当前的年份
month = p-tm_mon + 1;//获取本地当前的月份
while(1){
printf(\t\t %d 年%d 月\n,year,month);
printCalendar(year,month);
action =getch();
system(cls);
switch(action){
case KEYUP
year++;
break;
case KEYDOWN
year--;
break;
case KEYLEFT
month--;
if(month 1){
month = 12;
}
break;
case KEYRIGHT
month++;
if(month 12){
month = 1;
}
break;
}
}
}
//判断 year 是否是润年 返回 1 为闰年
const int isLeap(int year){
if(year%4==0year%100!=0||year%400==0){
return 1;
}
else{
return 0;
}
}
/*计算 year 年的 month 月是多少天
*返回值 :整型 ,天数
*/
const int getMonthDays(int year,int month){
switch(month){
case 1
case 3
case 5
case 7
case 8
case 10
case 12
return 31;
break;
case 4
case 6
case 9
case 11
return 30;
break;
case 2
if(isLeap(year)){
显示全部