万年历代码c语言CSDN,c语言万年历代码

匿名用户

1级

2013-11-11 回答

这个程序有一个功能是查询输入的一天是这一年的第几天

/* welcome to use the WanNianLi system!

孙辉

*/

#include

#include

#include

char* month_str[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};

char* week[]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};

int mon_day[]={31,28,31,30,31,30,31,31,30,31,30,31}; //初始化每个月的天数

int leap (int year)//判断闰年

{

if(year%4==0&&year%100!=0||year%400==0)

return 1;

else return 0;

}

int month_day(int year,int month) //判断这一个月有多少天

{

if(leap(year)&&month==2 )

return 29;

else

return(mon_day[month-1]); }

int firstday(int year,int month,int day)//判断这一个月的第一天是星期几

{

int c=0;

float s;

int m;

for(m=1;m

c=c+month_day(year,m);

c=c+day;

s=year-1+(float)(year-1)/4+(float)(year-1)/100+(float)(year-1)/400-40+c;

return ((int)s%7);

}

int printone(int a,int b) //打印出一个月的日历

{

printf(" --------------------------------------------------------------------------\n");

<
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是基于Keil软件的电子万年历代码示例: ```c #include <reg52.h> // 引用STC89C52芯片的头文件 #include <intrins.h> // 引用延时函数头文件 #define uchar unsigned char // 定义uchar为无符号字符类型 #define uint unsigned int // 定义uint为无符号整型 sbit SCLK=P3^6; // 定义时钟线 sbit DIO=P3^5; // 定义数据线 uchar code table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 }; // 定义共阳数码管显示码表 void delay(uint z) // 延时函数 { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void Write(uchar date) // 写入数据函数 { uchar i; for(i=0;i<8;i++) { SCLK=0; DIO=date&0x01; date>>=1; SCLK=1; } } void Init() // 初始化函数 { SCLK=0; Write(0x88); // 显示控制指令 Write(0x40); // 设置地址指令 Write(0xc8); // 设置扫描限制指令 Write(0x06); // 设置显示模式指令 Write(0x01); // 清屏指令 } void Display(uchar *p) // 显示函数 { uchar i; for(i=0;i<8;i++) { Write(0x44+i*2); // 设置地址指令 Write(p[i]); // 写入数据 } } void main() // 主函数 { uchar i,j,k,l; Init(); // 初始化 while(1) { for(i=0;i<24;i++) // 小时 { for(j=0;j<60;j++) // 分钟 { for(k=0;k<60;k++) // 秒钟 { for(l=0;l<100;l++) // 毫秒 { Display(table); // 显示时间 delay(1); // 延时1毫秒 } table[7]++; // 每秒加1 if(table[7]==0x3c) // 当毫秒数为60时 { table[7]=0; // 毫秒清零 table[6]++; // 秒钟加1 if(table[6]==0x3c) // 当秒钟数为60时 { table[6]=0; // 秒钟清零 table[5]++; // 分钟加1 if(table[5]==0x3c) // 当分钟数为60时 { table[5]=0; // 分钟清零 table[4]++; // 小时加1 if(table[4]==0x18) // 当小时数为24时 { table[4]=0; // 小时清零 } } } } } } } } } ``` 这是一个简单的电子万年历代码示例,可以根据需求进行修改。需要注意的是,该代码是基于STC89C52单片机开发的,如果使用其他型号的单片机,需要根据具体情况进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值