| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 740 人关注过本帖
标题:我自己写的万年历对不齐。。。。求高手看看哇
只看楼主 加入收藏
模糊
Rank: 2
等 级:论坛游民
帖 子:56
专家分:53
注 册:2013-2-26
收藏
得分:0 
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
int main(void)
{
    void title(int,int);
    int WEEK(int,int);
    void nianli(int,int,int);
    int year,month;
    int i,j;
        printf("\n\n");
        printf("\t######################################################\n");
        printf("\t######              年历显示                     #####\n");
        printf("\t######################################################\n");
        printf("\t######################################################\n");
        printf("\t######                                           #####\n");
        printf("\t######            1.查询年历                     #####\n");
        printf("\t######            2.查询日历                     #####\n");
        printf("\t######            3.查询具体日期和假期           #####\n");
        printf("\t######            0.退出程序                     #####\n");
        printf("\t######################################################\n");
        printf("\t######################################################\n");
        printf("\n\n");
        printf("\t\t\t您的选择是:");
        scanf("%d",&j);
        switch(j)
        {
        case 1:printf("\t请输入要查询的年份(如2013):");
        scanf("%d",&year);
        for(month=1;month<13;month++)
        {
            title(year,month);
            i=WEEK(year,month);
            nianli(i,month,year);
            printf("\n\n\n");
        }
        break;


        case 2:printf("\t请输入要查询的年月(如2013-02):");
        scanf("%d-%d",&year,&month);
        printf("\n\n");
        if(month<1&&month>12)
        {
            printf("\t请输入正确的月份。\n");
            break;
        }
        title(year,month);
        i=WEEK(year,month);
        nianli(i,month,year);
        printf("\n\n\n");
        getchar();
        break;

        case 3:
        case 0:exit(0);

        default:printf("\n\t请输入正确的序号\n");
        }
        return 0;
}

void title (int year,int month)
{
    printf("\n");
    printf("    *******************************************************\n   ");
    printf("              %d年                     %d月                \n",year,month);
    printf("    *******************************************************\n   ");
    printf("\t星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n    ");
}

void nianli(int i,int month,int year)
{
    const int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int a[32],m,j;
    int leap(int year);
    static int x=1;
    for(j=0;j<32;j++)
    a[j]=j;
        if(i>0)
    {
        for(;x<=i;x++) printf("     ");
    }
    if(leap(year)==1)
    {
    if(month==2)
    {
       for(m=1;m<=mon[2]+1;m++)
       {
           printf("\t%d",a[m]);
           if(x%7==0) printf("\n");
           x++;
       }
    printf("\n");
    }
        else
        for(m=1;m<=mon[month];m++)
    {
        printf("\t%d",a[m]);
        if(x%7==0) printf("\n");
        x++;
    }
    printf("\n");

    }
        else
    for(m=1;m<=mon[month];m++)
    {
        printf("\t%d",a[m]);
        if(x%7==0) printf("\n");
        x++;
    }
    printf("\n");
}

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


//******************************************************************

int WEEK(int year,int month)
{
    int week,c,y,i;
    if(month==1||month==2){month+=12;year-=1;}
    c=year/100;
    y=year-c*100;
    week=(int)(c/4)-2*c+y+(int)(y/4)+(int)(13*(month+1)/5);
    while(week<0)
    {
        week+=7;
    }
    week%=7;
    switch (week)
    {
    case 1: i=1; break;
    case 2: i=2; break;
    case 3: i=3; break;
    case 4: i=4; break;
    case 5: i=5; break;
    case 6: i=6; break;
    case 0: i=0; break;
    }
    return i;
}
这么就对齐了 但是 你看看吧
2013-02-26 20:09
模糊
Rank: 2
等 级:论坛游民
帖 子:56
专家分:53
注 册:2013-2-26
收藏
得分:0 
回复 8楼 兔司机
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
int main(void)
{
    void title(int,int);
    int WEEK(int,int);
    void nianli(int,int,int);
    int year,month;
    int i,j;
        printf("\n\n");
        printf("\t######################################################\n");
        printf("\t######              年历显示                     #####\n");
        printf("\t######################################################\n");
        printf("\t######################################################\n");
        printf("\t######                                           #####\n");
        printf("\t######            1.查询年历                     #####\n");
        printf("\t######            2.查询日历                     #####\n");
        printf("\t######            3.查询具体日期和假期           #####\n");
        printf("\t######            0.退出程序                     #####\n");
        printf("\t######################################################\n");
        printf("\t######################################################\n");
        printf("\n\n");
        printf("\t\t\t您的选择是:");
        scanf("%d",&j);
        switch(j)
        {
        case 1:printf("\t请输入要查询的年份(如2013):");
        scanf("%d",&year);
        for(month=1;month<13;month++)
        {
            title(year,month);
            i=WEEK(year,month);
            nianli(i,month,year);
            printf("\n\n\n");
        }
        break;


        case 2:printf("\t请输入要查询的年月(如2013-02):");
        scanf("%d-%d",&year,&month);
        printf("\n\n");
        if(month<1&&month>12)
        {
            printf("\t请输入正确的月份。\n");
            break;
        }
        title(year,month);
        i=WEEK(year,month);
        nianli(i,month,year);
        printf("\n\n\n");
        getchar();
        break;

        case 3:
        case 0:exit(0);

        default:printf("\n\t请输入正确的序号\n");
        }
        return 0;
}

void title (int year,int month)
{
    printf("\n");
    printf("    *******************************************************\n   ");
    printf("              %d年                     %d月                \n",year,month);
    printf("    *******************************************************\n   ");
    printf("\t星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六\n    ");
}

void nianli(int i,int month,int year)
{
    const int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int a[32],m,j;
    int leap(int year);
    static int x=1;
    for(j=0;j<32;j++)
    a[j]=j;
        if(i>0)
    {
        for(;x<=i;x++) printf("     ");
    }
    if(leap(year)==1)
    {
    if(month==2)
    {
       for(m=1;m<=mon[2]+1;m++)
       {
           printf("\t%d",a[m]);
           if(x%7==0) printf("\n");
           x++;
       }
    printf("\n");
    }
        else
        for(m=1;m<=mon[month];m++)
    {
        printf("\t%d",a[m]);
        if(x%7==0) printf("\n");
        x++;
    }
    printf("\n");

    }
        else
    for(m=1;m<=mon[month];m++)
    {
        printf("\t%d",a[m]);
        if(x%7==0) printf("\n");
        x++;
    }
    printf("\n");
}

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


//******************************************************************

int WEEK(int year,int month)
{
    int week,c,y,i;
    if(month==1||month==2){month+=12;year-=1;}
    c=year/100;
    y=year-c*100;
    week=(int)(c/4)-2*c+y+(int)(y/4)+(int)(13*(month+1)/5);
    while(week<0)
    {
        week+=7;
    }
    week%=7;
    switch (week)
    {
    case 1: i=1; break;
    case 2: i=2; break;
    case 3: i=3; break;
    case 4: i=4; break;
    case 5: i=5; break;
    case 6: i=6; break;
    case 0: i=0; break;
    }
    return i;
}
这么就对齐了 但是还有点问题 你看看吧
收到的鲜花
  • 兔司机2013-02-27 09:12 送鲜花  3朵  
2013-02-26 20:11
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
收藏
得分:0 
回复 12楼 模糊
大神。。。你查询下年历或者闰年月历都没对齐。。。我也不知道哪里错了。
2013-02-27 09:08
快速回复:我自己写的万年历对不齐。。。。求高手看看哇
数据加载中...
 
   



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

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