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'을 사용하는 것이 옳지 않다고 생각합니다. –