| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 720 人关注过本帖
标题:自己遍了一个日历的软件,新手可以拿来看看,也请高手帮我指点一下
取消只看楼主 加入收藏
飞扬冲天
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:86
专家分:122
注 册:2011-10-21
结帖率:66.67%
收藏
 问题点数:0 回复次数:1 
自己遍了一个日历的软件,新手可以拿来看看,也请高手帮我指点一下
#include <stdio.h>

void main()
{
    void printcalendar(int year);
    int year,choice;
    printf("My First C Program:    Calendar\n\n");
    printf("Please Input The Year:\n");
    printf("(Input '0' to exit)\t--\t");
    while(1)
    {
    printf("Please Input The Year:\t");
    scanf("%d",&year);
    if(year==0)
        break;
    putchar('\n');
    printcalendar(year);
    putchar('\n');
    }
}

void printmonth(int month,int year);

void printcalendar(int year)
    {
        int month;

        for(month=1;month<=12;month++)
        {printmonth(month,year);printf("\n");}
    }

void printmonth(int month,int year)
    {

        char *month_name(int month);
        int month_days(int month,int year);
        int first_day(int month,int year);
        int day,weekday,n,days;
        char *p;

        weekday=first_day(month,year);
        p=month_name(month);
        days=month_days(month,year);

        printf("   ==%s     %d年/%d月\n",p,year,month);
        printf("Mon Tue Wen Thu Fri Sat Sun\n");


        for(n=0;n<weekday;n++)
           {printf("    ");}
        for(day=1;day<=days;day++)
        {
            printf(" %-2d ",day);
            weekday+=1;
            if(weekday%7==0)
            {
                putchar('\n');

            }
            if(weekday==8)weekday=1;
        }
    }

char *month_name(int month)
{
    char *p_name;
    char *str[]={"January",
                 "February",
                 "March",
                 "April",
                 "May",
                 "June",
                 "July",
                 "August",
                 "September",
                 "October",
                 "November",
                 "December"};

    p_name=*(str+(month-1));
    return (p_name);
}
int isleapyear(int year);

int month_days(int month,int year)
{

    switch(month)
    {
        case 1:return 31;
        case 2:if(isleapyear(year))return 29;
                 return 28;
        case 3:return 31;
        case 4:return 30;
        case 5:return 31;
        case 6:return 30;
        case 7:return 31;
        case 8:return 31;
        case 9:return 30;
        case 10:return 31;
        case 11:return 30;
        case 12:return 31;
    }
}

int isleapyear(int year)
{
    if(((year%4==0)&&(year%100!=0))||(year%400==0))
        return 1;
    return 0;
}

int first_day(int month,int year)
{
    int i,l=0,monthdays,n=0;
    static int sumdays;
    monthdays=month_days(month-1,year);
    if(month==1)
    {
        for(i=1;i<year;i++)
     {
         if(isleapyear(i))
           l+=1;
         else n+=1;

     }
     return (sumdays=(n*365+l*366)%7);
    }
   return (sumdays=(sumdays+monthdays)%7);

}

搜索更多相关主题的帖子: 软件 include choice 日历 
2011-12-09 21:49
飞扬冲天
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:86
专家分:122
注 册:2011-10-21
收藏
得分:0 
回复 2楼 zy_space
哦,嗯谢谢,我明天看一看。我们C语言还没有学到那里去
2011-12-09 23:51
快速回复:自己遍了一个日历的软件,新手可以拿来看看,也请高手帮我指点一下
数据加载中...
 
   



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

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