vc6.0 程序编译出现错误 怎么回事
源程序如下:#include<stdio.h>#defineM5#defineN5intmain(void){inta[M,N];intb[M,N];intc[M,N];...
源程序如下:
#include <stdio.h>
#define M 5
#define N 5
int main(void)
{
int a[M,N];
int b[M,N];
int c[M,N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i,j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j,i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i,j] + c[i,j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i,j] - c[i,j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i,j] * c[i,j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
出现错误:
G:\C语言\20100420.c(8) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(8) : error C2059: syntax error : 'constant'
G:\C语言\20100420.c(9) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(9) : error C2059: syntax error : 'constant'
G:\C语言\20100420.c(10) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(10) : error C2059: syntax error : 'constant' 展开
#include <stdio.h>
#define M 5
#define N 5
int main(void)
{
int a[M,N];
int b[M,N];
int c[M,N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i,j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j,i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i,j] + c[i,j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i,j] - c[i,j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i,j] * c[i,j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
出现错误:
G:\C语言\20100420.c(8) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(8) : error C2059: syntax error : 'constant'
G:\C语言\20100420.c(9) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(9) : error C2059: syntax error : 'constant'
G:\C语言\20100420.c(10) : error C2143: syntax error : missing ']' before ','
G:\C语言\20100420.c(10) : error C2059: syntax error : 'constant' 展开
4个回答
展开全部
#include <stdio.h>
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i < m;i++)
{
for (j =0;j < n;j ++)
{
scanf("%d",&a[i][j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
scanf("%d",&b[i][j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
scanf("%d",&c[i][j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i < m;i ++)
{
for (j = 0;j <n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i < m;i++)
{
for (j = 0;j <n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i < m;i ++)
{
for (j = 0;j <n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
你的二维数组定义和表示错了,应该是array[][]。还有数组的下标是从0开始的,比如一个二维数组a[3][3]它的元素个数为9个分别为a[0][0],a[0][1],a[0][2],a[1][0],a[1][1],a[1][2],a[2][0],a[2][1],a[2][2]。你在输入和输出时用了<=就错了,要用<。
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i < m;i++)
{
for (j =0;j < n;j ++)
{
scanf("%d",&a[i][j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
scanf("%d",&b[i][j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
scanf("%d",&c[i][j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i < m;i ++)
{
for (j = 0;j <n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i < m;i++)
{
for (j = 0;j <n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i < m;i ++)
{
for (j = 0;j < n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i < m;i ++)
{
for (j = 0;j <n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
你的二维数组定义和表示错了,应该是array[][]。还有数组的下标是从0开始的,比如一个二维数组a[3][3]它的元素个数为9个分别为a[0][0],a[0][1],a[0][2],a[1][0],a[1][1],a[1][2],a[2][0],a[2][1],a[2][2]。你在输入和输出时用了<=就错了,要用<。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i][j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i][j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i][j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
你上面的问题全出在二维数组的定义上面,二维数组定义为data[][]形式,而不是你的那样。
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i][j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i][j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i][j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
你上面的问题全出在二维数组的定义上面,二维数组定义为data[][]形式,而不是你的那样。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
#define M 5
#define N 5
int main(void)
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,t,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
唔……我帮你改好了,以下程序可行。
#include <stdio.h>
#include <iostream>
using namespace std;
#define M 5
#define N 5
void main()
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
#include <stdio.h>
#include <iostream>
using namespace std;
#define M 5
#define N 5
void main()
{
int a[M][N];
int b[M][N];
int c[M][N];
int i,j,m,n,k,p;
printf("Please enter the number m & n:");
scanf("%d %d",&m,&n);
printf("Please enter the first Array:");
for ( i = 0;i <= m;i ++)
{
for (j =0;j <= n;j ++)
{
scanf("%d",&a[i,j]);
}
}
printf("Please enter the second Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&b[i,j]);
}
}
printf("Please enter the third Array:");
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
scanf("%d",&c[i,j]);
}
}
printf("Please enter the number k & p:");
scanf("%d %d",&k,&p);
switch(p)
{
case 1:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j ++)
{
printf("%d",k*a[i][j]);
}
printf("\n");
}
break; //矩阵的数乘
case 2:
for (i = 0;i <= m;i++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[j][i]);
}
printf("\n");
}
break; // 这个程序不对
case 3:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j++)
{
printf("%d",b[i][j] + c[i][j]);
}
printf("\n");
}
break; //矩阵的加法
case 4:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <= n;j ++)
{
printf("%d",b[i][j] - c[i][j]);
}
printf("\n");
}
break; //矩阵的减法
case 5:
for (i = 0;i <= m;i ++)
{
for (j = 0;j <=n;j++)
{
printf("%d",b[i][j] * c[i][j]);
}
printf("\n");
}
break; //矩阵的乘法
default:
printf("Input error!\n");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询