| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1024 人关注过本帖, 2 人收藏
标题:学着别人写万年历,可总不成功,帮忙看看原因
只看楼主 加入收藏
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
回复 10楼 hepigzhang
感谢感谢,十分感谢,你的话对我这样自学的人太有帮助了,平时总觉得自己很细致,没想到第一次写点东西就有这多错误

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-10-31 08:47
青春无限
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江苏
等 级:贵宾
威 望:24
帖 子:3452
专家分:19340
注 册:2012-3-31
收藏
得分:0 
学习

学 会看代码…学习写程序…学会搞开发…我的目标!呵呵是不是说大话啊!!一切皆可能
2012-10-31 10:13
龙航四海
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:58
专家分:102
注 册:2012-10-17
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>   
printk(int k);   
main()
{
 char month_name[12][9]={"January","February","March","April","May","June",
     "July","August","September","October","November","December"};
 char weekday_name[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"},a[6][7];
 int  month_day[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
 {0,31,29,31,30,31,30,31,31,30,31,30,31}};
 do
 {
int leap,year,month,day,FirstDay_Year,FirstDay_Month,i,j,num;
printf("input a year num:");
scanf("%5d",&year);
if(year==0)
exit(1);
printf("输入查询月份1--12:");
 scanf("%3d",&month);
 leap=year%4==0&&year%100!=0||year%400==0 ; //如果该语句为真,则为闰年,leap为1,否则为0
FirstDay_Year=5*(year/4)+(year%4)-(year/100)+(year/400);//0--6(0表示星期日)

for(i=1,day=0;i<month;i++)
    day=day+month_name[leap][i];
    FirstDay_Month=(day+FirstDay_Year)%7;

for(num=1,i=0,j=FirstDay_Month;num<=month_day[leap][month];num++)
{
a[i][j]=num;
if((j+1)%7==0)
i++;
j=(j+1)%7;
}

printf("THE Calendar of Year %d\n",year);
printf("%d\t",month);
printf(" SUN MON TUE WED THU FRI SAT");

for(num=1,printf("\n\t"),i=0,j=FirstDay_Month;num<=month_day[leap][month];num++)
{
    if(num==1)
    {
        printk(j);
    }   
    printf("%4d",a[i][j]);
        if((j+1)%7==0)
        {
        i++;
        printf("\n\t");
        }
        j=(j+1)%7;
}
printf("\n");
 }while(1);
}
printk(int k)
{
    int s;
    for(s=0;s<4*k;s++)
        printf(" ");
}
我的这个输出没问题,就是月与月之间的连接有问题,嘿嘿!
2012-10-31 23:01
xtjopt
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:89
专家分:168
注 册:2012-9-12
收藏
得分:0 
新手学习了
2012-10-31 23:34
心定事成
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2012-10-29
收藏
得分:0 
请看看如下修改
#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 04:59
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
其实真的不爱用do...while循环,因为个人认为FOR可以解决现阶段所有循环问题

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-01 09:42
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
#include<stdio.h>
#include<stdlib.h>
char month_name[13][6]={"","JAN","FEB","MAR","APR","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
char week_name[7][6]={"sun","mon","tue","wed","thu","fir","sat"};
int month_day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int month2[6][7];

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

int calendar(int year)
{

    int month;
    int weekday;
    int i,j,k,t=0,x;
    if(leapyear(year))month_day[2]=29;
    else month_day[2]=28;
    weekday=(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;


    for(month=1;month<=12;month++)
    {    t=0;
            for(i=0;i<6;i++)
    for(j=0;j<7;j++)
    month2[i][j]=0;
        scanf("%d",&x);
        for(k=1;k<=month_day[month];k++)
        {
            month2[t][weekday]=k;
            weekday++;
            if(weekday==7)
            {
                weekday=0;
                t++;
            }
        }
     print1(month);
    }
}

print1(int month)
{
    int i,j,p,m=0;
    printf("=====%s=====\n",month_name[month]);
    for(p=0;p<7;p++)
    printf("%7s",week_name[p]);
    printf("\n");
    for(i=0;i<6;i++)
    for(j=0;j<7;j++)
    {   if(month2[i][j]==0)
        printf("%7c",32);
        else
        printf("%7d",month2[i][j]);
        m++;
        if(m%7==0)
        {
            printf("\n");
        }

     }
     printf("\n");
}

main()
{
    int year;
    printf("qing shu ru nian fen:\n");
    scanf("%d",&year);
        printf("*****%d*****",year);
    calendar(year);
    system("puse");
    getch();
}
解决了 ,真的很艰难,

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2012-11-01 09:50
guoyungg
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2012-11-1
收藏
得分:0 
我的能力只是顶上去
2012-11-01 10:47
快速回复:学着别人写万年历,可总不成功,帮忙看看原因
数据加载中...
 
   



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

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