| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 424 人关注过本帖
标题:万年历程序问题
只看楼主 加入收藏
黄建军
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-10-22
结帖率:0
收藏
已结贴  问题点数:10 回复次数:3 
万年历程序问题
#include<stdio.h>
#include <time.h>
int leap_or_common(int year)
{
    if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
        return 1;
    else return 0;
}
int count_year(int day, int *q)
{
    int n = 0, i;
    i = leap_or_common(1970);
    while((i == 1 && day > 366) || (i ==0 && day > 365))
    {
        if(i == 1)
            day-= 366;
        else
            day-= 365;
        n++;
        i = leap_or_common(1970 + n);
    }
    *q = day;
    return 1970 + n;
}
int judge(int year,int month)
{
    if(month==1||month==3||month == 5||month==7||month==8||month==10||month==12)
    return(1);
    else if(month==2)
    {
        if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
            return(2);
        else     return(3);
    }
    else     return(4);

}
int count_month(int year, int day, int *q)
{
    int month = 1;
    while(1)
    {
        if(month % 2 != 0 && month <= 7 && day >= 31)
        {
            day -= 31;
            month++;
        }
        else if(month == 2 && ((leap_or_common(year) == 1 && day >= 29) || (leap_or_common(year) == 0) && day >= 28))
        {
            day = day - 28 - leap_or_common(year);
            month++;
        }
        else if(month > 2 && month < 7 && month % 2 == 0 && day >= 30)
        {
            day -= 30;
            month++;
        }
        else if(month >= 8 && month % 2 == 0 && day >= 31)
        {
            day -= 31;
            month++;
        }
        else if(month > 8 && month % 2 != 0 && day >= 30)
        {
            day -= 30;
            month++;
        }
        else
            break;
    }
    *q = day;
    return month;
}
int main(void)
{
    int second, day, month, year, date, remind,i,j,k,a,n,m,count=0,count1=0,count2=0,count3=0,count4=0;
    char **p;
    char *week[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    second = time(NULL);
    day = second / (60 * 60 * 24) + 1;
    year = count_year(day, &remind);
    day = remind;
    month = count_month(year,day, &remind);
    printf("   ========================================\n");
    printf("     今天是%d年%d月%d日.\n",year,month,remind);
    printf("   ========================================\n");
    if(year%4!=0||year%100==0&&year%400!=0)
        count++;
    for(i=1;i<month;i++)
    {
        if(i==1||i==3||i == 5||i==7||i==8||i==10||i==12)
        count1++;
        else if(i==2)
        {
            if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
              count2++;
            else     count3++;
        }
        else     count4++;
    }
   
    a=year*365+count+count1*31+count2*28+count3*29+count4*30-9;
   
        n=judge(year,month);
        
                for(j=0;j<7;j++)
                {
                    p=week+j;
                        printf("%6s",*p);

                }
                    printf("\n");
                    for(k=0;k<(a+1)%7;k++)
                            printf("   ");
                    for(m=1;m<32;m++)
                    {
                        
                            printf("%6d",m);
                            if((a+m)%7==0)
                                    printf("\n");
                            if(n==1&&m==31)
                                break;
                            else if(n==2&&m==28)
                                break;
                            else if(n==3&&m==29)
                                break;
                            else if(n==4&&m==30)
                                break;
                    }
                    
                    printf("\n");
                                    
                    printf("    =======================================\n");
    return 0;

}
那位大侠帮看看错误在哪里并帮忙改下 此程序的目的是输出本月日历,我这个程序的错误在于十月份的是正确的其他月份的是错误的
改好了且有能帮忙提意见的发到我的qq邮箱541040017@谢谢!

搜索更多相关主题的帖子: include 万年历 400 return 
2012-10-22 19:58
黄建军
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-10-22
收藏
得分:0 
怎么就没人回复下
2012-10-26 18:23
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:5 
还真没尝试过编写万年历
因为有现成的万年历控件 拿过来就用了


另:谁改好了给你发邮箱里  感觉你的语气就像是领导命令下属一样  嘿嘿

DO IT YOURSELF !
2012-10-26 18:31
青春无限
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江苏
等 级:贵宾
威 望:24
帖 子:3451
专家分:19340
注 册:2012-3-31
收藏
得分:5 
看看

学 会看代码…学习写程序…学会搞开发…我的目标!呵呵是不是说大话啊!!一切皆可能
2012-10-26 18:33
快速回复:万年历程序问题
数据加载中...
 
   



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

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