Write a function that can be called to find the largest element of an m by n matrix.
#include <stdio.h>
void largest(int A[20][20]);
void main()
{
int Arr[20][20],i,j;
clrscr();
printf("Enter 5x5 matrix elements \n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&Arr[i][j]);
largest(Arr);
getch();
}
void largest(int A[20][20])
{
int i,j,k,l,max,p1,p2;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
max=A[i][j];
p1=i;
p2=j;
for(k=1;k<=5;k++)
{
for(l=1;l<=5;l++)
{
if(A[k][l]>max)
{
max=A[k][l];
p1=k;
p2=l;
}
}
}
}
}
printf("The largest element is A[%d][%d] and the value is %d",p1,p2,max);
}
#include <stdio.h>
void largest(int A[20][20]);
void main()
{
int Arr[20][20],i,j;
clrscr();
printf("Enter 5x5 matrix elements \n");
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&Arr[i][j]);
largest(Arr);
getch();
}
void largest(int A[20][20])
{
int i,j,k,l,max,p1,p2;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
max=A[i][j];
p1=i;
p2=j;
for(k=1;k<=5;k++)
{
for(l=1;l<=5;l++)
{
if(A[k][l]>max)
{
max=A[k][l];
p1=k;
p2=l;
}
}
}
}
}
printf("The largest element is A[%d][%d] and the value is %d",p1,p2,max);
}
No comments:
Post a Comment