C语言网

 找回密码
 加入社区!

QQ登录

只需一步,快速开始

查看: 1124|回复: 7

自己做的日历(C语言)   [复制链接]

Rank: 1

主题
0
帖子
4
C币
13 枚
在线时间
2 小时
发表于 2010-8-13 23:18:36 |显示全部楼层
本帖最后由 kekeyu 于 2010-8-15 16:59 编辑

一部分抄袭维他C
  1. /*Creat-by EvE*/
  2. /*亿淫帝国地址:www.yiyindiguo.freeforums.org*/
  3. /*C语言社区地址:www.cbbs.freeforums.org*/
  4. /*亿淫帝国QQ群:109559204*/

  5. /*VC++6.0编译*/
  6. #include "stdio.h"
  7. #include "conio.h"
  8. #include "stdlib.h"
  9. int main()
  10. {
  11.         void print_calendar(int year,int month);    //打印日历
  12.         void first_set(int *year,int *month);       //初始设定年月
  13.         int days_of_month(int year,int month);      //某年某月一共多少天
  14.         int firstday_of_month(int year,int month);  //某年某月第一天星期几
  15.         int year,month;
  16.         char ch;
  17.         first_set(&year,&month);
  18.         while(1)
  19.         {  print_calendar(year,month);
  20.            do{
  21.               ch=getch();
  22.                      if(ch=='p'||ch=='P')
  23.                        {  month-=1;
  24.                           if(month<1) {month=12;year-=1;}
  25.                        }
  26.                      else if(ch=='n'||ch=='N')
  27.                        {  month+=1;
  28.                           if(month>12) {month=1;year+=1;}
  29.                        }
  30.                      else if(ch=='e'||ch=='E')
  31.                        {  exit(0);
  32.                        }
  33.              }while(ch!='n'&&ch!='N'&&ch!='p'&&ch!='P');
  34.         }
  35.     return 0;
  36. }

  37. void print_calendar(int year,int month)
  38. {  int i,firstday=firstday_of_month(year,month);
  39.    int days=days_of_month(year,month);
  40.    system("cls");
  41.    printf("\t\t\t\t%d年%d月",year,month);
  42.    printf("\n\n********************************************************************************\n\n");
  43.    printf("\t\t\t  日  一  二  三  四  五  六\n");
  44.    printf("\t\t\t");
  45.    for (i=0;i<firstday;i++)
  46.       printf ("%4c",' ');
  47.    for(i=firstday;i<firstday+days;i++)
  48.    {  if(i%7==0&&i!=0) printf("\n\t\t\t");
  49.              printf("%4d",i-firstday+1);
  50.    }
  51.    printf("\n\n********************************************************************************\n\n");
  52.    printf("\t\t********e退出 p上一月 n下一月********");
  53. }

  54. void first_set(int *year,int *month)
  55. {  do{
  56.            printf ("please input the year(1~9999):");
  57.        scanf ("%d",year);
  58.        if(*year<1||*year>9999) printf ("WANNING:ERROR,please input again!\n");
  59.      }while (*year<1||*year>9999);
  60.    do{
  61.        printf ("please input the month(1~12):");
  62.        scanf ("%d",month);
  63.        if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");
  64.      }while (*month<1||*month>12);
  65. }

  66. int days_of_month(int year,int month)
  67. {   int i;
  68.         if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) i=31;
  69.         else if(month==4||month==6||month==9||month==11) i=30;
  70.         else if(month==2&&(year&&4==0&&year%100!=0||year%400==0)) i=29;
  71.         else i=28;
  72.         return i;
  73. }

  74. int firstday_of_month(int year,int month)
  75. {   long z=(year-1)*365+1;
  76.     int i;
  77.     for (i=1;i<year;i++)
  78.        if ((i%4==0&&i%100!=0)||(i%400==0)) z++;
  79.     for(i=1;i<month;i++)
  80.        z+=days_of_month(year,i);         
  81.     return z%7;
  82. }
复制代码



1

查看全部评分

Rank: 1

主题
0
帖子
1
C币
1 枚
在线时间
0 小时
发表于 2010-8-15 17:26:47 |显示全部楼层
试了意下  很好用 挺简便得 呵呵~~

Rank: 1

主题
2
帖子
21
C币
19 枚
在线时间
2 小时
发表于 2010-9-9 20:56:01 |显示全部楼层
额,TC下不行.......

Rank: 1

主题
0
帖子
7
C币
7 枚
在线时间
1 小时
发表于 2010-10-17 10:19:52 |显示全部楼层
TC也行,只是要加入中文支持符集

Rank: 1

主题
2
帖子
17
C币
21 枚
在线时间
0 小时
发表于 2010-10-17 10:24:35 |显示全部楼层
这个可以带走~
老师正好让我们做一个日历来
谢谢楼主哈

Rank: 1

主题
0
帖子
2
C币
3 枚
在线时间
1 小时
发表于 2010-11-10 21:23:37 |显示全部楼层
真不错,谢谢了

Rank: 1

主题
0
帖子
2
C币
2 枚
在线时间
0 小时
发表于 2010-12-5 19:21:26 |显示全部楼层
不错,正在疯狂学习C呢,这个可以拿来研究,嘿嘿~

Rank: 1

主题
0
帖子
10
C币
10 枚
在线时间
1 小时
发表于 2011-1-17 09:29:23 |显示全部楼层
--------------------配置: mingw5 - CUI Release, 编译器类型: MinGW--------------------

检查文件依赖性...
正在编译 D:\My Documents\C-Free\Temp\未命名8.cpp...
[Error] D:\My Documents\C-Free\Temp\未命名8.cpp:67: error: expected primary-expression before "int"
[Error] D:\My Documents\C-Free\Temp\未命名8.cpp:67: error: expected primary-expression before "int"
[Error] D:\My Documents\C-Free\Temp\未命名8.cpp:67: error: `firstday_of_month' was not declared in this scope
[Error] D:\My Documents\C-Free\Temp\未命名8.cpp:69: error: `days_of_month' was not declared in this scope

构建中止 未命名8: 4 个错误, 0 个警告

头痛!
您需要登录后才可以回帖 登录 | 加入社区!

C语言 ( 粤ICP备11042647号-2 )

GMT+8, 2012-2-7 23:11

©2009-2011 cyuyan.com.cn

回顶部