| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1333 人关注过本帖
标题:用C写的日历程序源码
取消只看楼主 加入收藏
一夕落叶
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-1-2
收藏
 问题点数:0 回复次数:0 
用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
快速回复:用C写的日历程序源码
数据加载中...
 
   



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

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