登录|立即注册|使用QQ帐号登录
论坛 > Windows/CE
发帖|
看13339|回6|收藏
ID:85681 看全部
2015-7-15 02:24
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int Year=2012;
int Month=4;
int MonthDays[] = {31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};
char IsLeapYear(int Year)
{
    if((Year % 4 == 0 && Year % 100 != 0) || Year % 400 == 0)
    {
        return 1 ;
    }
    else
    {
        return 0 ;
    }
}
int GetFirstDay(int year,int month,int day)
{
int week=0;
int c=0,y=0;
if (month==1)
{
  year--;
  month=13;
}
if (month==2)
{
  year--;
  month=14;
}
c=year/100;
y=year%100;
week=(c/4)-2*c+y+(y/4)+(26*(month+1)/10)+day-1;
week%=7;
if (week<0)
{
  week+=7;
}
return week;
}
void DisMonthDays(int year,int month)
{
int i;
int tmp=0;
int week=0;
printf("       %d 年 %d 月\n",year,month);
printf("日  一  二  三  四  五  六\n");
tmp=MonthDays[month-1];
if (month==2)
{
  if (IsLeapYear(year))
  {
   tmp=MonthDays[month-1]+1;
  }
  else
   tmp=MonthDays[month-1];
}
week=GetFirstDay(year,month,1);
for(i=0;i<week;i++)
{
  printf("    ");
}
for(i=1;i<=tmp;i++)
{
  printf("%2d  ",i);
  if (week>=6)
  {
   week=0;
   printf("\n");
  }
  else
   week++;
}
}
void GetKey()
{
int key;
key = getche();
if(key==224)
{
  key = getche();
  if (key==72)
  {
   Month++;
   if (Month>12)
   {
    Month=1;
    Year++;
   }
  }
  else
   if (key==80)
   {
    Month--;
    if (Month<1)
    {
     Month=12;
     Year--;
    }
   }
}
}
void main(void)
{
while (1)
{
  DisMonthDays(Year,Month);
  GetKey();
  printf("\n");
  system("cls");
}
}















ID:58110 看全部
2018-4-5 07:01
老师您好,能分享一下完整的程序吗
谢谢

ID:320397 看全部
2018-5-3 15:26
楼上的这个已经是完整的代码了




可编译的,我上图编译成功了.
附件列表
日历2.PNG (2018-5-3 15:26 上传)

原图尺寸 41.34 KB, 下载次数: 214

日历2.PNG

日历.PNG (2018-5-3 15:25 上传)

原图尺寸 16.44 KB, 下载次数: 207

日历.PNG

ID:370231 看全部
2019-3-8 14:21

谢谢!51黑有你更精彩!
ID:1065225 看全部
2023-3-5 23:22
楼主这个十分有趣,不知道对于闰年和400年这个也是好评
ID:253767 看全部
2023-8-29 09:05
DEV C++运行该程序出错:[Error]“::main”必须返回“int”。
原程序:void main(void)
{
  while (1)
  {
    DisMonthDays(Year,Month);
    GetKey();
    printf("\n");
    system("cls");
  }
}
ID:289698 看全部
2024-5-9 21:11
牛,当教材学习了

51黑电子论坛

Powered by Discuz! X3.1

首页|标准版|触屏版|电脑版