| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1331 人关注过本帖
标题:用C写的日历程序源码
只看楼主 加入收藏
一夕落叶
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-1-2
收藏
 问题点数:0 回复次数:4 
用C写的日历程序源码
#include<stdio.h>
main()
{
    int i,j,day,year,temp,temp_i ;
    long int year_days ;
    long int sumdays(int year);
    int IsLeapYear(int year);
    int month_day[]=
    {
        0,31,28,31,30,31,30,31,31,30,31,30,31,29
    };
   
    int everyday[6][14];
    printf("please enter the year :\n");
    scanf("%d",&year);
    printf("\n\n");
    year_days=sumdays(year);
    for(temp=1;temp<=6;temp++)
    {
        for(i=0;i<6;i++)
        for(j=0;j<14;j++)
        everyday[i][j]=0 ;
        switch(temp)
        {
            case 1 :
            printf("\tJanuary   %d\t\t\tFebruary %d\n",year,year);
            break ;
            case 2 :
            printf("\tMarch     %d\t\t\tApril    %d\n",year,year);
            break ;
            case 3 :
            printf("\tMay       %d\t\t\tJune     %d\n",year,year);
            break ;
            case 4 :
            printf("\tJuly      %d\t\t\tAugust   %d\n",year,year);
            break ;
            case 5 :
            printf("\tSeptember %d\t\t\tOctober  %d\n",year,year);
            break ;
            case 6 :
            printf("\tNovember  %d\t\t\tDecember %d\n",year,year);
            break ;
        }
        printf("Mon Tue Wed Thu Fri Sat Sun    Mon Tue Wed Thu Fri Sat Sun");
        printf("\n");
        i=j=0 ;
        for(temp_i=0;temp_i<(year_days%7);temp_i++)
        everyday[0][j++]=0 ;
        day=1 ;
        while(day<=month_day[2*temp-1])
        {
            if(j%7==0)
            j=0,i++;
            everyday[i][j++]=day ;
            year_days++;
            day++;
        }
        i=0,j=7 ;
        for(temp_i=0;temp_i<(year_days%7);temp_i++)
        everyday[0][j++]=0 ;
        day=1 ;
        if(IsLeapYear(year)&&2*temp==2)
        while(day<=month_day[13])
        {
            if(j%14==0)
            j=7,i++;
            everyday[i][j++]=day ;
            year_days++;
            day++;
        }
        else
        while(day<=month_day[2*temp])
        {
            if(j%14==0)
            j=7,i++;
            everyday[i][j++]=day ;
            year_days++;
            day++;
        }
        for(i=0;i<6;i++)
        {
            for(j=0;j<14;j++)
            {
                if(everyday[i][j]!=0)
                printf("% -4d",everyday[i][j]);
                else
                printf("    ");
                if(j==6)
                printf("  ");
            }
            printf("\n");
            
        }
        if(getch()=='q')
        exit(0);
    }
    getch();
}
int IsLeapYear(int year)
{
    if((year%4==0)&&(year%100!=0)||(year%400==0))
    return 1 ;
    else
    return 0 ;
}
long int sumdays(int year)
{
    int year_start=1,leapsum=0 ;
    while(year_start<year)
    {
        if(IsLeapYear(year_start))
        leapsum++;
        year_start++;
    }
   
    return 366*leapsum+365*(year-leapsum);
}
搜索更多相关主题的帖子: int year 源码 temp 日历 
2008-03-21 20:47
icedar
Rank: 1
等 级:新手上路
帖 子:11
专家分:3
注 册:2008-2-13
收藏
得分:0 
可惜了, 没有注释,看源码很费力啊。而且,没有注明是在什么环境编译,不知VC++ 6.0可不可以?

[ 本帖最后由 icedar 于 2010-5-23 18:42 编辑 ]
2010-05-23 18:39
longlong89
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:广州
等 级:小飞侠
威 望:6
帖 子:1043
专家分:2754
注 册:2009-8-18
收藏
得分:0 

想象力征服世界
2010-05-23 19:01
kekeyu
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-8-14
收藏
得分:0 
我以前做的,呵呵。

程序代码:
/*Creat-by EvE*/
/*亿淫帝国地址:www.yiyindiguo.*/
/*C语言社区地址:www.cbbs.*/
/*亿淫帝国QQ群:109559204*/

/*VC++6.0编译*/
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
int main()
{
    void print_calendar(int year,int month);    //打印日历
    void first_set(int *year,int *month);       //初始设定年月
    int days_of_month(int year,int month);      //某年某月一共多少天
    int firstday_of_month(int year,int month);  //某年某月第一天星期几
    int year,month;
    char ch;
    first_set(&year,&month);
    while(1)
    {  print_calendar(year,month);
       do{
          ch=getch();
             if(ch=='p'||ch=='P') 
               {  month-=1;
                  if(month<1) {month=12;year-=1;}
               }
             else if(ch=='n'||ch=='N')
               {  month+=1;
                  if(month>12) {month=1;year+=1;}
               }
             else if(ch=='e'||ch=='E')
               {  exit(0);
               }
         }while(ch!='n'&&ch!='N'&&ch!='p'&&ch!='P'); 
    }
    return 0;
}

void print_calendar(int year,int month)
{  int i,firstday=firstday_of_month(year,month);
   int days=days_of_month(year,month);
   system("cls");
   printf("\t\t\t\t%d年%d月",year,month);
   printf("\n\n********************************************************************************\n\n");
   printf("\t\t\t  日  一  二  三  四  五  六\n");
   printf("\t\t\t");
   for (i=0;i<firstday;i++)
      printf ("%4c",' ');
   for(i=firstday;i<firstday+days;i++)
   {  if(i%7==0&&i!=0) printf("\n\t\t\t");
         printf("%4d",i-firstday+1);
   }
   printf("\n\n********************************************************************************\n\n");
   printf("\t\t********e退出 p上一月 n下一月********");
}

void first_set(int *year,int *month)
{  do{
       printf ("please input the year(1~9999):");
       scanf ("%d",year);
       if(*year<1||*year>9999) printf ("WANNING:ERROR,please input again!\n");
     }while (*year<1||*year>9999);
   do{
       printf ("please input the month(1~12):");
       scanf ("%d",month);
       if(*month<1||*month>12) printf ("WANNING:ERROR,please input again!\n");
     }while (*month<1||*month>12);
}

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

int firstday_of_month(int year,int month)
{   long z=(year-1)*365+1;
    int i;
    for (i=1;i<year;i++)
       if ((i%4==0&&i%100!=0)||(i%400==0)) z++;
    for(i=1;i<month;i++)
       z+=days_of_month(year,i);         
    return z%7;
}


运行结果:
[local]1[/local]
2010-08-14 10:42
kekeyu
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-8-14
收藏
得分:0 
版主果然太坏了
2010-08-14 18:36
快速回复:用C写的日历程序源码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015732 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved