标题:我自己写的万年历对不齐。。。。求高手看看哇
取消只看楼主
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
结帖率:0
已结贴  问题点数:20 回复次数:5 
我自己写的万年历对不齐。。。。求高手看看哇
#include <stdio.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");
        }
}

void title (int year,int month)
{
    printf("\n");
    printf("    *******************************************************\n   ");
    printf("              %d年                     %d月                \n",year,month);
    printf("    *******************************************************\n   ");
    printf("   星期日  星期一  星期二  星期三  星期四  星期五  星期六\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("%8d",a[m]);
           if(x%7==0) printf("\n");
           x++;
       }
    printf("\n");
    }
        else
        for(m=1;m<=mon[month];m++)
    {
        printf("%8d",a[m]);
        if(x%7==0) printf("\n");
        x++;
    }
    printf("\n");

    }
        else
    for(m=1;m<=mon[month];m++)
    {
        printf("%8d",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;
}
搜索更多相关主题的帖子: void 万年历 include title 
2013-02-26 18:02
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
得分:0 
回复 2楼 未微电子
坐等高手。。谢谢啦
2013-02-26 18:06
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
得分:0 
回复 5楼 xxbuer
好吧。。。不是这不是关键= = 关键是我那个星期和数字对不齐。。
2013-02-26 19:23
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
得分:0 
回复 6楼 模糊
我错了啦。。但是能想方法对齐星期嘛- -
2013-02-26 19:24
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
得分:0 
回复 4楼 yuccn
用的CFREE和VC都试过了。。对不齐呀。。星期和日期对不齐,你可以编译试试
2013-02-26 19:25
兔司机
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-2-26
得分:0 
回复 12楼 模糊
大神。。。你查询下年历或者闰年月历都没对齐。。。我也不知道哪里错了。
2013-02-27 09:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-399227-1-1.html




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

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