{
int temp,i,j,m=(n-1)/2;
for(i=0;i<=m;i++)
{j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;}
return;
}
main()
{
int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("The original array:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf("The array has been inverted:\n");
for(i=0;i<=10;i++)
printf("%d,"a[i]);
printf("\n");
}
系统编译的时候说
Error C:\TURBOC2\FLY.C 1:Declartion syntax error
这是为什么?
----------------解决方案--------------------------------------------------------
viod inv(int x[],int n) /*此处错误viod改为void*/
{
int temp,i,j,m=(n-1)/2;
for(i=0;i<=m;i++)
{j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;}
return;
}
main()
{
int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("The original array:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf("The array has been inverted:\n");
for(i=0;i<=10;i++)
printf("%d,"a[i]); /*此处错误改为printf("%d",a[i])*/
printf("\n");
}
系统编译的时候说
Error C:\TURBOC2\FLY.C 1:Declartion syntax error
这是为什么?
----------------解决方案--------------------------------------------------------
还是不行
还是Error C:\TURBOC2\FLY.C 1:Declartion syntax error
----------------解决方案--------------------------------------------------------
改成这样:
inv(int x[],int n)
{
int temp,i,j,m=0;
m=(n-1)/2;
for(i=0;i<=m;i++)
{j=n-1-i;
temp=x[i];x[i]=x[j];x[j]=temp;}
return;
}
main()
{
int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("The original array:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf("The array has been inverted:\n");
for(i=0;i<=10;i++)
printf("%d",a[i]);
printf("\n");
}
----------------解决方案--------------------------------------------------------
我调试了,程序没有错误,我用的win-tc
----------------解决方案--------------------------------------------------------
# include <stdio.h>
void inv(int a[],int n)
{
int temp,i,j,m=(n-1)/2;
for(i=0;i<=m;i++)
{j=n-1-i;
temp=a[i];a[i]=a[j];a[j]=temp;}
}
void main()
{
int i,a[10]={3,7,9,11,0,6,7,5,4,2};
printf("The original array:\n");
for(i=0;i<10;i++)
printf("%d,",a[i]);
printf("\n");
inv(a,10);
printf("The array has been inverted:\n");
for(i=0;i<=10;i++)
printf("%d",a[i]);
printf("\n");
}
try again.
----------------解决方案--------------------------------------------------------
这是谭浩强书上的例题,
----------------解决方案--------------------------------------------------------
恩 是的 可是我运行却出现错误
我用的是TURBO C 2.0
----------------解决方案--------------------------------------------------------
2楼给你改的很对啊,可以啊 就是TURBO C 2.0
你仔细看看
----------------解决方案--------------------------------------------------------
好了 现在运行正确了
----------------解决方案--------------------------------------------------------