万年历代码急求:万年历c代码 显示 属相 时间 日期 农历
万年历代码 时间:2021-08-03 阅读:(
)
c语言中编写万年历的代码要用到那些函数?
#include"stdio.h"
#define YES 1
#define NO 0
int isleap(int year)
{
int leap=NO;
if(year%4==0 && year%100!=0 || year%400==0)
leap = YES;
return leap;
}
int week_of_firstday(int year)
{
int n;
n=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
return n;
}
int main()
{
int year,month,day,weekday,len_of_month,i;
printf("请输入年份:");
scanf("%d",&year);
weekday=week_of_firstday(year);
for(month=1;month<=12;month++)
{
printf("
"); printf(" %d年%d月
",year,month);
printf("---------------------
");
printf("日 一 二 三 四 五 六
");
printf("---------------------
");
for(i=0;i<weekday;i=i+1)
printf(" ");
if(month==4||month==6||month==9||month==11)
len_of_month=30;
else if(month==2)
{
if(isleap(year))
len_of_month=29;
else
len_of_month=28;
}
else
len_of_month=31;
for(day=1;day<=len_of_month;day++)
{
if(day>9)
printf("%d ",day);
else
printf("%d ",day);
weekday++;
if(weekday==7)
{
weekday=0;
printf("
");
}
}
printf("
");
}
return 0;
}求万年历代码 一定要C++的 最好全面点
一个万年历的C++实现代码
#include < iostream >
#include < iomanip >
using namespace std;
int FistDayofYear( int y);
int DaysofMonth( int m);
void PrintMonth( int m);
void PrintHead( int m);
bool LeapYear( int y);
int WeekDay,year;
void main()
{
INPUT:
cerr << " 请输入年份(>1): " ;
cin >> year;
WeekDay = FistDayofYear(year);
cout << "
" << year << " 年
" ;
cout << " ========================================================== " ;
for ( int a = 1 ;a < 13 ;a ++ )
PrintMonth(a);
cout << endl;
int r = 0 ,u = 0 ;
cout << " 继续打1,退出打0 : " ;
cin >> r;
if (r > u)
goto INPUT;
else
goto END;
END:;
}
void PrintMonth( int m)
{
PrintHead(m);
int day = DaysofMonth(m);
for ( int i = 1 ;i <= day;i ++ )
{
cout << setw( 5 ) << i;
WeekDay = (WeekDay + 1 ) % 7 ;
if (WeekDay == 0 )
{
cout << endl;
cout << setw( 5 ) << " " ;
}
}
}
void PrintHead( int m)
{
cout << "
" << setw( 5 ) << m;
cout << " 月 日 一 二 三 四 五 六
" ;
cout << setw( 5 ) << " " ;
for ( int i = 0 ;i < WeekDay;i ++ )
cout << setw( 5 ) << " " ;
}
int DaysofMonth( int m)
{
switch (m)
{
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 : return 31 ;
case 4 :
case 6 :
case 9 :
case 11 : return 30 ;
case 2 : if (LeapYear(year)) return 29 ;
else return 28 ;
}
return 0 ;
}
bool LeapYear( int y)
{
return (y % 4 == 0 && y % 100 != 0 || y % 400 == 0 );
}
int FistDayofYear( int y)
{
long m;
m = y * 365 ;
for ( int i = 1 ;i < y;i ++ )
m += LeapYear(i);
return m %= 7 ;
}急求:万年历c代码 显示 属相 时间 日期 农历
/*
* 程序名称: 万年历
* 功能描述: 在字符界面下显示万年历的功能.
* 设计编程: 董小向
* 时 间: 2007-5
*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#define CURU 72
#define CURD 80
#define CURL 75
#define CURR 77
#define ESC 27
void printWNL(int, int); //简单格式打印万年历
void printWNL2(int, int); //打印带表格的万年历
int Week(int,int,int); //求星期几
int getDays(int, int); //计算某个月的天数
int isRunNian(int); //判断是否闰年
/*
*主函数,应用程序入口
*/
void main()
{
int year,month;
struct tm t;
char ch;
_getsystime(&t); //标准函数, 获得系统当前时间
year = t.tm_year + 1900; //得到当前年份
month = t.tm_mon + 1; //得到当前月份
do
{
system("cls"); //调用DOS清屏命令
printWNL(year,month); //自定义函数, 打印万年历
ch = getch(); //获得无回显控制台输入字符
if(ch == ESC) //ESC键,退出循环,结束程序
break;
else if(ch == 0) //若值为零,则用户敲了功能键,继续获取后续代码。
ch = getch();
switch(ch)
{
case CURL: year--; break; //左键减年
case CURR: year++; break; //右键加年
case CURU: //上键减月
month--;
if(month == 0)
{
month = 12;
year--;
}
break;
case CURD: //下键加月
month++;
if(month == 13)
{
month = 1;
year++;
}
break;
default:;
}
}while(1);
printf("
谢谢使用,欢迎常来!再见。
");
}
/*
*简单格式打印万年历
*参数: y 整型,接收年份值; m 整型,接收月份值;
*返回值: 无
*/
void printWNL(int y, int m)
{
int i,j;
int day = 1 - Week(y,m,1); //天数初始值,定位1号的位置
int days = getDays(y,m);
printf(" %4d年%2d月
",y,m);
printf(" 日 一 二 三 四 五 六
");
for(i = 1; i <= 6; i++)
{
for(j = 1; j <= 7; j++)
{
if(day <= 0 || day > days)
printf(" ");
else
printf("%3d",day);
day++;
}
printf("
");
}
printf(" 提示:【←】减年 【→】加年 【↑】减月 【↓】加月 【ESC】退出
");
}
/*
*求星期几
*参数: y 整型,接收年份值; m 整型,接收月份值; d 整型,接收天的号数
*返回值: 整型, 是0,1-6七个数之间的一个数,0代表星期日,1-6代表星期一至星期六
*/
int Week(int y,int m,int d)
{
int days = 0; //总天数
int i;
for(i = 1; i < y; i++) //累计1到y-1年的天数
days += isRunNian(i) ? 366 : 365;
for(i = 1; i < m; i++) //累计y年第1月到第m-1月的天数
days += getDays(y,i);
days += d; //累计当月的天数。
return days % 7; //返回星期值
}
/*
*判断是否闰年
*参数: y 整型, 接收年份值
*返回值: 整型, 只为0或1, 0代表假, 1代表真
*/
int isRunNian(int y)
{
return (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) ? 1 : 0;
}
/*
*计算某个月的天数
*参数: y 整型,接收年份值; m 整型,接收月份值;
*返回值: 整型, 是0, 28, 29, 30, 31之间的一个数
*注意: 返回值为0,表示你调用该函数时传递了不正确的年份值或月份值.
*/
int getDays(int y, int m)
{
int days = 0;
switch(m)
{
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:
days = isRunNian(y) ? 29 : 28; break;
default:;
}
return days;
}
void printWNL2(int y, int m)
{
int i,j;
int day = 1 - Week(y,m,1); //天数初始值,定位1号的位置
int days = getDays(y,m);
printf("
╔══════════════════════════╗");
printf("
╔══万年历 查询═════════════════╗║
");
printf(" ║ %4d 年 %2d 月 ║║
",y,m);
printf(" ╟———┬———┬———┬———┬———┬———┬———╢║
");
printf(" ║ 日 │ 一 │ 二 │ 三 │ 四 │ 五 │ 六 ║║
");
for(i = 1; i <= 6; i++)
{
printf(" ╟———┼———┼———┼———┼———┼———┼———╢║
");
printf(" ║");
for(j = 1; j <= 7; j++)
{
if(day <= 0 || day > days)
printf(" ");
else
printf(" %2d ",day);
j < 7 ? printf("│") : i < 6 ? printf("║║") : printf("║╝");
day++;
}
printf("
");
}
printf(" ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╝
");
printf(" 提示:【←】减年 【→】加年 【↑】减月 【↓】加月 【ESC】退出
");
}
hostkvm在2021年3月新上线洛杉矶新VPS业务,强制三网接入中国联通优化线路,是当前中美之间性价比最高、最火热的线路之一,性价比高、速度非常好,接近联通AS9929和电信AS4809的效果,带宽充裕,晚高峰也不爆炸。 官方网站:https://hostkvm.com 全场优惠码:2021(全场通用八折,终身码,长期) 美国 US-Plan0【三网联通优化线路】 内存:1G CPU:...
零途云(Lingtuyun.com)新上了香港站群云服务器 – CN2精品线路,香港多ip站群云服务器16IP/5M带宽,4H4G仅220元/月,还有美国200g高防云服务器低至39元/月起。零途云是一家香港公司,主要产品香港cn2 gia线路、美国Cera线路云主机,美国CERA高防服务器,日本CN2直连服务器;同时提供香港多ip站群云服务器。即日起,购买香港/美国/日本云服务器享受9折优惠,新...
TMThosting发布了今年黑色星期五的促销活动,即日起到12月6日,VPS主机最低55折起,独立服务器9折起,开设在西雅图机房。这是一家成立于2018年的国外主机商,主要提供VPS和独立服务器租用业务,数据中心包括美国西雅图和达拉斯,其中VPS基于KVM架构,都有提供免费的DDoS保护,支持选择Windows或者Linux操作系统。Budget HDD系列架构CPU内存硬盘流量系统价格单核51...
万年历代码为你推荐
upperupper-intermediate是什么意思hd4600CPU集成高性能HD4600核心显卡,好不好trapezoid人体各个骨头的英文单词安全防护谈谈你对自我安全防护的看法,如何保障自身安全和企业安全?ucosiiucosii是什么?里面的OS是指什么?在看正点原子给的stm32f407开发指南的时候看到这个,什么意思?订单详情请问拼多多如何查看订单详情?怎么将购买的订单详情全部导出?电子听诊器听诊器有哪些用途的知识实数的定义实数的概念是什么,实数包括0吗?蓝牙开发蓝牙技术到底是指什么?赵锡成美国杰出华人
日本vps 免费域名解析 草根过期域名 kvmla 香港主机 搜狗12306抢票助手 免费ddos防火墙 eq2 华为4核 中国智能物流骨干网 建立邮箱 赞助 新家坡 卡巴斯基试用版 gtt 酷番云 台湾谷歌 丽萨 ledlamp 114dns 更多