标题:求解下万年历
只看楼主
aa120824371
Rank: 2
来 自:广东汕头
等 级:论坛游民
帖 子:11
专家分:14
注 册:2012-10-30
结帖率:25%
已结贴  问题点数:10 回复次数:9 
求解下万年历
求个高手教下  万年历月历第一个星期前面的空格要怎么弄   (注:因为我课本才看到了for 麻烦弄点我能看得懂的谢谢)
搜索更多相关主题的帖子: 课本 月历 万年历 
2012-10-30 08:57
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:5 
网上搜的  不知道是否准确  自己验证

#include<stdio.h>
#include<stdlib.h>
int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
/*数组monthday[13]存放每个月的天数*/
char monthname[13][6]={"","JAN","FEB","MAR","APR","MAY","JUNE",
                                        "JULY","AUG","SEP","OCT","NOV","DEC"};
/*数组monthname[][]存放每个月的英文名称,用于打印*/
char weekday[8][6]={"SUN","MAN","TUE","WED","THU","FRI","SAT","SUM"};
/*数组weekday[][]存放一周的每一天的英文名称,用于打印*/
int month2[6][7];
int leapyear(int year)
/*函数1:判断year是否为闰年*/
{if((year%4==0)&&(year%100)!=0||(year%400)==0)
  return 1;
 else
  return 0;
}
void print2(int month,int t)
/*函数2:按月打印日历*/
{ int i,j;
  printf("***  %s  ***\n",monthname[month]);
  for(i=0;i<=6;i++)
     printf("%5s",weekday[i]);
  printf("\n");
  for(i=0;i<=t;i++)
   {for(j=0;j<=6;j++)
        if(month2[i][j]==0)
    printf("      ");
       else
     printf("%5d",month2[i][j]);
     printf("\n");
   }
}
void calendar(int year)
/*函数3:主体函数,按月生成日历*/
{int month;
 int todayweek,today,i,j,t;
 if(leapyear(year))
  monthday[2]=29;
 else
  monthday[2]=28;
 todayweek=year+(year-1)/4-(year-1)/100+(year-1)/400;
 todayweek=todayweek%7;
 /*计算当年第1天是星期几*/
 printf("===  year   %d  ===\n",year);
  for(month=1;month<=12;month++)
   {today=1;
    for(i=0;i<=5;i++)
       for(j=0;j<=5;j++)
        month2[i][j]=0;
     t=0;
     while(today<=monthday[month])
      {month2[t][todayweek]=today;
        todayweek++; today++;
         if(todayweek==7)
          {todayweek=0;
           t++;
          }
      }
    print2(month,t);
    }
}
main()
{int year;
 printf("请输入年份:\n");
 scanf("%d",&year);
 calendar(year);
system("pause");
}

DO IT YOURSELF !
2012-10-30 09:01
青春无限
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江苏
等 级:贵宾
威 望:24
帖 子:3450
专家分:19340
注 册:2012-3-31
得分:0 
学习

学 会看代码…学习写程序…学会搞开发…我的目标!呵呵是不是说大话啊!!一切皆可能
2012-10-30 09:04
w995612220
Rank: 5Rank: 5
等 级:职业侠客
威 望:1
帖 子:139
专家分:313
注 册:2012-6-20
得分:0 
发现楼上的天天蹭分。。
2012-10-30 10:13
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
得分:0 
此问题高贵不贵,简单实惠
2楼发的是正确的,复制下来只要改改就能运行,我正在研究它。涉及到C的很多东西,好好研究它有助于掌握知识,比我在网上找的那些题好太多了,主要是涉及面广,不再只是某一部分只是。
号召和我一样的新手一起研究

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-10-30 14:17
姻脂梦
Rank: 6Rank: 6
等 级:侠之大者
帖 子:264
专家分:424
注 册:2012-7-3
得分:0 
也来蹭个分
2012-10-30 16:37
心定事成
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2012-10-29
得分:4 
这样修改,就可以运行了
#include<stdio.h>
#include<stdlib.h>
int monthday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
/*数组monthday[13]存放每个月的天数*/
char monthname[13][6]={"","JAN","FEB","MAR","APR","MAY","JUNE",
                                        "JULY","AUG","SEP","OCT","NOV","DEC"};
/*数组monthname[][]存放每个月的英文名称,用于打印*/
/*char weekday[8][6]={"SUN","MAN","TUE","WED","THU","FRI","SAT","SUN"};*/
char weekday[8][9]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日"};
/*数组weekday[][]存放一周的每一天的英文名称,用于打印*/
int month2[6][7];

int leapyear(int year)
/*函数1:判断year是否为闰年*/
{if((year%4==0)&&(year%100)!=0||(year%400)==0)
  return 1;
else
  return 0;
}

void print2(int month,int t)
/*函数2:按月打印日历*/
{ int i,j;
  printf("***  %s  ***\n",monthname[month]);
  for(i=0;i<=6;i++)
     printf("%-8s",weekday[i]);
  printf("\n");
  for(i=0;i<=t;i++)
   {for(j=0;j<=6;j++)
        if(month2[i][j]==0)
            printf("%8s"," ");//printf("      ");
          else
             printf("%3s%-5d"," ",month2[i][j]);
        printf("\n");
   }
}
void calendar(int year)
/*函数3:主体函数,按月生成日历*/
{int month;
int todayweek,today,i,j,t;
if(leapyear(year))
  monthday[2]=29;
else
  monthday[2]=28;
todayweek=year+(year-1)/4-(year-1)/100+(year-1)/400;
todayweek=todayweek%7;
/*计算当年第1天是星期几*/
printf("===  year   %d  ===\n",year);
  for(month=1;month<=12;month++)
   {today=1;
    for(i=0;i<=5;i++)
       for(j=0;j<=6;j++)
            month2[i][j]=0;/*清空*/
     t=0;
     while(today<=monthday[month])
      {month2[t][todayweek]=today;
        todayweek++; today++;
         if(todayweek==7)
          {todayweek=0;
           t++;
          }
      }
    print2(month,t);
    }
}

main()
{int year;
printf("请输入年份:\n");
scanf("%d",&year);
printf("     一切有为法,如梦幻泡影,如露亦如电,应作如是观。\n\n");
calendar(year);
system("pause");
}

一切有为法,如梦幻泡影,如露亦如电,应作如是观。
2012-11-01 05:33
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
得分:0 
功夫不负苦心人,万年历研究成功,绝对完美

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-01 09:37
hfhf2006
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:62
专家分:169
注 册:2012-6-29
得分:0 
祝贺O(∩_∩)O哈哈~
2012-11-01 11:04
龙航四海
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:58
专家分:102
注 册:2012-10-17
得分:1 
printk(int k)
{
    int s;
    for(s=0;s<4*k;s++)
        printf(" ");
}
这里的k决定于当月的第一天星期几,而4*k,是因为我输出每个日期是%4d,希望能帮到你
2012-11-01 14:50



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




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

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