Sample input
Enter the size of the matrix
3
Enter the elements
1
2
3
4
5
6
7
8
9
Smallest elements in each row are
1
4
7
Largest elements in each column are
7
8
9
Common element in both row and column is 7
Smallest element in each row ex-
Largest element in each column are
PROGRAM
#include<stdio.h>
int main()
{
int n,i,j;
printf("Enter the size of matrix");
scanf("%d",&n);
int a[n][n];
int rowmin[n];
int columnmax[n];
printf("Enter the elements:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
rowmin[i]=a[i][0];
for(j=0;j<n;j++)
{
if(a[i][j]<rowmin[i])
{
rowmin[i]=a[i][j];
}
}
}
for(i=0;i<n;i++)
{
columnmax[i]=a[0][i];
for(j=0;j<n;j++)
{
if(a[j][i]>columnmax[i])
{
columnmax[i]=a[j][i];
}
}
}
printf("\n");
printf("smallest elemebt in each row are\n");
for(i=0; i<n; i++)
{
printf("%d\n",rowmin[i]);
}
printf("\n");
printf("largest elements in each column are\n");
for(i=0; i<n; i++)
{
printf("%d\n",columnmax[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(rowmin[i]==columnmax[j])
{
printf("The common in both row and column is %d\t", rowmin[i]);
}
}
}
}
in this example we write a program that take smallest elements in each row and largest element in each column, and print common elements in them.
in this program first we enter a number that represents the size of the square matrix.
then we scan the nxn matrix.
then we write a code to take the smallest element in each row and then we write the code to take the largest elements in each column. then we write a code to print the common elements in them.