首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

急求c大牛解决输出日历有关问题!

2012-03-29 
急求c大牛解决输出日历问题!!#includestdio.h#includestdlib.hint x,year,month,startDay,days,dayin

急求c大牛解决输出日历问题!!
#include<stdio.h>
#include<stdlib.h>
int x,year,month,startDay,days,day;
int isLeap(int year);
int GetMonthDays(int year,int month);
int GetWeekDay(int year,int month,int day);
void PrintMonthCalender(int startDay,int days);
main()
{
  printf("Please input year and month:");
  scanf("%d %d",year,month);
  printf("The result is:\n");
  PrintMonthCalender(startDay,days);
}
int isLeap(int year)

  int m1,m2,m3;
  m1=year%4;
  m2=year%100;
  m3=year%400;
  if((0==m1&&0!=m2)||(0==m3))
  {
  return 1;
  }
  else
  {
  return 0;
  }
  }
int GetMonthDays(int year,int month)
{
x=isLeap(year);
if(1==x) //x代表判断闰年的返回值
{
switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
return 31;break;
case 4:case 6:case 9:case 11:
return 30;break;
case 2:
return 29;break;
default:printf("Your input is wrong.\n");break;
}
}
else
{
  switch(month)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
return 31;break;
case 4:case 6:case 9:case 11:
return 30;break;
case 2:
return 28;break;
default:printf("Your input is wrong.\n");break;
}
}
}
int GetWeekDay(int year,int month,int day)
{
int days,y,s=0,k,weekDay;
if(1==x)
{
k=29;
}
if(0==x)
{
k=28;
}
y=year-1;
switch(month-1)
{
case 12:s=s+31;
case 11:s=s+30;
case 10:s=s+31;
case 9:s=s+30;
case 8:s=s+31;
case 7:s=s+31;
case 6:s=s+30;
case 5:s=s+31;
case 4:s=s+30;
case 3:s=s+31;
case 2:s=s+k;
case 1:s=s+31;
}
s=s+day;
days=y*365+y/400+y/4-y/100+s;
weekDay=days%7;
return weekDay;
}
void PrintMonthCalender(int startDay,int days)
{
int i=1,count,t=0,w;
w=GetMonthDays(year,month);
startDay=GetWeekDay(year,month,1);
printf("\t\t\t%d-%d\n",year,month);
printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");
count=startDay;
while(i<=w)
{
while(t<count)
{
printf("\t");
t=t++;
}
while(count<=7)
{
printf("%d\t",i);
i=i++;
count=count++;
}
printf("\n");
count=1;
}
printf("\n");

什么地方错了??运行后就直接提示程序错误,我是学生,急求大牛帮助,谢谢

[解决办法]

C/C++ code
#include<stdio.h>#include<stdlib.h>int isLeap(int year);int GetMonthDays(int year,int month);int GetWeekDay(int year,int month,int day);void PrintMonthCalender(int year, int month);int main(){    int year,month;    printf("Please input year and month:");    scanf("%d %d",&year,&month);    printf("The result is:\n");    PrintMonthCalender(year,month);     return 0;}int isLeap(int year){      int m1,m2,m3;    m1=year%4;    m2=year%100;    m3=year%400;    if( (0==m1&&0!=m2) || (0==m3) )    {        return 1;     }     else    {        return 0;    }}int GetMonthDays(int year,int month){    int x=isLeap(year);    if(1 == x) //x代表判断闰年的返回值    {        switch(month)        {        case 1:case 3:case 5:case 7:case 8:case 10:case 12:            return 31;break;        case 4:case 6:case 9:case 11:            return 30;break;        case 2:            return 29;break;        default:printf("Your input is wrong.\n");exit(0);break;         }    }    else    {        switch(month)        {        case 1:        case 3:        case 5:        case 7:        case 8:        case 10:        case 12:            return 31;            break;        case 4:        case 6:        case 9:        case 11:            return 30;break;        case 2:            return 28;            break;        default:printf("Your input is wrong.\n");            exit(0);            break;        }    }    return 0;}int GetWeekDay(int year,int month,int day){    int days,y,s=0,k,weekDay;    int x=isLeap(year);    if(1==x)    {        k=29;    }    if(0==x)    {        k=28;    }     y=year-1;    switch(month-1)    {    case 12:        s=s+31;    case 11:        s=s+30;    case 10:        s=s+31;    case 9:        s=s+30;    case 8:        s=s+31;    case 7:        s=s+31;    case 6:        s=s+30;    case 5:        s=s+31;    case 4:        s=s+30;    case 3:        s=s+31;    case 2:        s=s+k;    case 1:        s=s+31;    }    s=s+day;    days=y*365+y/400+y/4-y/100+s;    weekDay = days % 7;    return weekDay;}void PrintMonthCalender(int year,int month){    int startDay;    int i=1,count,t=1,w;    w=GetMonthDays(year,month);    startDay=GetWeekDay(year,month,1);    printf("\t\t\t%d-%d\n",year,month);    printf("Sun.\tMon.\tTue.\tWed.\tThu.\tFri.\tSat.\n");    count=startDay;    while( i <= w )    {        while(t < count )        {            printf("\t");            t++;        }        while(count<=7 && i <= w )        {            printf("%d\t",i);            i++;            count++;        }        printf("\n");        count=1;    }    printf("\n");}  //有一些修改 自己看吧 

热点排行