把有限数组改为无限数组时遇到的问题
程序是解决“求鞍点(该位置上的元素在其所在行最大列最小)问题”原程序定义的是数组范围是3*4 改成让用户定义数组范围
#include<stdio.h> #include<stdio.h>
#define n 3 int main()
#define m 4 {
int main() int i,j,n,m,a[n][m],max[n],min[m],flag=0;
{ printf("请确定矩阵的范围\nrow= colum= \n");
int i,j,a[n][m],max[n],min[m],flag=0; scanf("%d%d",&n,&m);
printf("\nplease input the array:\n"); 后面的就和左边一样
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
printf("the array you have input is:\n");
for(i=0;i<n;i++)
{for(j=0;j<m;j++)
printf("%4d",a[i][j]);printf("\n");}
for(i=0;i<n;i++)
{
max[i]=a[i][0];
for(j=0;j<m;j++)
if(a[i][j]>max[i])max[i]=a[i][j];
printf("max%d=%d ",i,max[i]);
}
for(j=0;j<m;j++)
{
min[j]=a[0][j];
for(i=0;i<n;i++)
if(a[i][j]<min[j])min[j]=a[i][j];
printf("min%d=%d ",j,min[j]);
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(max[i]==min[j]){flag=1;
printf("the an dian shi a[%d][%d]=%d\n",i,j,a[i][j]);
}
if(flag==0)
printf(" meiyou andian!\n");
getch();
}
运行左边程序没问题但是运行右边时出现
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2057: expected constant expression
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2466: cannot allocate an array of constant size 0
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2057: expected constant expression
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2466: cannot allocate an array of constant size 0
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2087: '<Unknown>' : missing subscript
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2133: 'a' : unknown size
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2057: expected constant expression
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2466: cannot allocate an array of constant size 0
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2133: 'max' : unknown size
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2057: expected constant expression
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2466: cannot allocate an array of constant size 0
D:\Microsoft Visual Studio\c程序\cheshi.c(3) : error C2133: 'min' : unknown size
D:\Microsoft Visual Studio\c程序\cheshi.c(37) : warning C4013: 'getch' undefined; assuming extern returning int
这是什么情况 问题出现在哪里