【发布时间】:2020-12-06 09:29:11
【问题描述】:
我尝试制作一个程序来显示二维数组列中的最大数字,但是这个程序有问题 这不能产生预期的结果。在我的编译器中说:
3 5 [Note] expected 'int *' but argument is of type 'int (*)[(sizetype)(b)]'
这是我的代码:
#include<stdio.h>
int array2d(int *x, int a, int b){
int i,j;
int max[j];
for(i=0; i<a ; i++){
max[j]= *x;
for(j=0; j<b ; j++){
if(*x>max[j])
{
max[j]=*x;
}
}
printf("\nthe maximum value of each column is : %d", max[j]);
}
int main(){
int a,b,i,j;
printf("enter the size of array (rows) & (column) : ");
scanf("%d %d",&a,&b);
int x[a][b];
printf("enter the number : ");
for ( i = 0; i < a; i++)
{
for ( j = 0; j < b; j++)
{
scanf("%d",&x[i][j]);
}
}
array2d(x,a,b);
return 0;
}
程序输入:
4 4
并输入号码:
1 3 2 1
8 4 3 2
1 2 3 4
9 8 7 6
并且期望这个输出:
9 8 7 6
我应该怎么做才能修复它?我需要您的意见,也许有人想帮助我编写正确的代码。
【问题讨论】:
-
查看this answer相关问题
-
看完还是没看懂@BasileStarynkevitch
-
那你需要读一本C编程的好书,比如Modern C。读完那本书后,请参阅 this website 并阅读一些 C 草案标准,例如 n1570
标签: c pointers multidimensional-array implicit-conversion function-declaration