当前位置: 代码迷 >> C语言 >> [求助]为什么在TC下可以运行在FREE下就不行了呢?
  详细解决方案

[求助]为什么在TC下可以运行在FREE下就不行了呢?

热度:320   发布时间:2006-10-14 12:13:59.0
[求助]为什么在TC下可以运行在FREE下就不行了呢?

#include"stdio.h"
void weekday();
int _2000yera(int x)
{
int sum=0;
int i;
if(x>=2000){
for(i=2000;i<x;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (sum+6)%7;
}
else{
for(i=x;i<2000;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (-sum%7+6)%7;
}

}
void weekday()
{
int i;
for(i=1;i<=7;i++)
printf("%d\t",i);
printf("\n");
}
int sp(int x)
{
int i;
for(i=1;i<=_2000yera(x);i++)
printf("\t");
return i;
}
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:
return leap(x)?29:28;
}
}
int leap(int x)
{
return x%4==0&&x%100!=0||x%400==0?0:1;
}
int printyear(int x)
{
int mon,i=1,j,day;
printf("*********1*********");
weekday();
printf("\n");
i=sp(x);
for(day=1,mon=1;mon<=12;mon++)
{
for(j=1;j<=month(mon,x);j++,i++,day++)
{
printf("%d\t",j);
if(i%7==0){printf("\n");day=1;}
}
if(mon<12){
printf("\n");
printf("*********%d*********\n",mon+1);
weekday();
printf("\n");
i=1;
i+=day-2;
for(;day-2>0;day--)
printf(" \t");}
}
}
main()
{
int x;
printf("year:");
scanf("%d",&x);
printyear(x);
getch();
}

在C-Free 3.5下 就是死循环啊
在TC下可以啊



搜索更多相关的解决方案: FREE  sum  int  weekday  

----------------解决方案--------------------------------------------------------
我在GCC下都没有事
----------------解决方案--------------------------------------------------------

那怎么会师啊
刚刚系统还说
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:
return leap(x)?29:28;
}
}
着句有问题啊


----------------解决方案--------------------------------------------------------

#include"stdio.h"
void weekday();
int _2000yera(int x)
{
int sum=0;
int i;
if(x>=2000){
for(i=2000;i<x;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (sum+6)%7;
}
else{
for(i=x;i<2000;i++)
{
sum+=(i%4==0&&i%100==0||i%400==0)?366:365;
}
return (-sum%7+6)%7;
}

}
int leap(int x)
{
return x%4==0&&x%100!=0||x%400==0?0:1;
}

void weekday()
{
int i;
for(i=1;i<=7;i++)
printf("%d\t",i);
printf("\n");
}
int sp(int x)
{
int i;
for(i=1;i<=_2000yera(x);i++)
printf("\t");
return i;
}
int month(int ch,int x)
{
switch(ch)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:return 31;
case 4:
case 6:
case 9:
case 11:return 30;
case 2:
return leap(x)?29:28;
}
}

int printyear(int x)
{
int mon,i=1,j,day;
printf("*********1*********");
weekday();
printf("\n");
i=sp(x);
for(day=1,mon=1;mon<=12;mon++)
{
for(j=1;j<=month(mon,x);j++,i++,day++)
{
printf("%d\t",j);
if(i%7==0){printf("\n");day=1;}
}
if(mon<12){
printf("\n");
printf("*********%d*********\n",mon+1);
weekday();
printf("\n");
i=1;
i+=day-2;
for(;day-2>0;day--)
printf(" \t");}
}
}
main()
{
int x;
printf("year:");
scanf("%d",&x);
printyear(x);
//getch();
}

/*函数要求定义在调用之前,除非前面有函数声明.你就是犯这个错误.*/


----------------解决方案--------------------------------------------------------
int leap(int x)
{
return x%4==0&&x%100!=0||x%400==0?0:1;
}
着句不是挺好的吗~
----------------解决方案--------------------------------------------------------
函数是很好,但你的函数定义在函数调用之后了,同时你也没有声明.所以出错.
----------------解决方案--------------------------------------------------------
int 的不是可以不用声明的吗
----------------解决方案--------------------------------------------------------
好了耶 斑竹就是斑竹 就是不一般
----------------解决方案--------------------------------------------------------
以下是引用mp3aaa在2006-10-14 16:06:52的发言:
int 的不是可以不用声明的吗

谁说不用了. 都是函数,应该没这个特殊吧.
要么在定义之前调用,要么就先写好声明.
----------------解决方案--------------------------------------------------------

哦哦


----------------解决方案--------------------------------------------------------