You can try code below to find maximum & minimum from a matrix of any order.
Code :
#include<stdio.h>
void acc(int [5][5],int,int);
void maxmin(int [5][5],int,int);
void main()
{
int a[5][5],r,c;
printf("\n\t\t**Smallest & largest no. from matrix**\n");
printf("\n\tEnter the size of row:\n\t");
scanf("%d",&r);
printf("\tEnter the size of column:\n\t");
scanf("%d",&c);
acc(a,r,c);
maxmin(a,r,c);
}
void acc(int m[5][5],int r,int c)
{
int i,j;
printf("\n\tenter the elements of matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\telement[%d][%d]= ",i,j);
scanf("%d",&m[i][j]);
}
}
}
void maxmin(int m[5][5],int r, int c)
{
int max=m[0][0], min=m[0][0],i,j;
for (i=0; i<r; i++)
{
for (j=0; j<c; j++)
{
if(m[i][j]>max)
max= m[i][j];
if(m[i][j]<min)
min= m[i][j];
}
}
printf("\n\tGreatest no. is : %d\n",max);
printf("\n\tSmallest no. is : %d\n",min);
}
复制 - 粘贴而不是键入它从你的代码;也许“真实”的代码有更多的错误,但没有通过这篇文章。另外,显示你正在调用这个函数的代码。我怀疑如果'MAXrow'和'MAXcol'不同,那么在这两个维度上使用'n'是不对的。 –