Input a two-dimensional integer array (n rows, m columns), then there may be array elements with the following characteristics in the two-dimensional integer array: its value in its row is the largest, and its value in its column value is minimal.

1. Topic content

Write a C program to achieve the following functions:
Input a two-dimensional integer array (n rows, n columns), then there may be array elements with the following characteristics in the two-dimensional integer array: it has the largest value in the row where it is located , which has the smallest value in its column.
If there is such an array element in the array, please output the row number and column number of the element; if there is no such array element in the array, output "there is no element of this feature".

2. Superficial analysis of the topic

1. The user determines the number of columns and rows, and uses an array to save all elements.
2. Find the maximum value element of each row, and then judge whether the element is the minimum value of the column element. If so, output the element and jump out Loop, if there is no output, the element does not exist
3. Use for loop to compare

3. Source code and in-depth analysis

#include <stdio.h>
#define N 10
void main()
{
    
    
 int n,i,j;
 int a[N][N];
 void search(int (*p)[N],int n);
 printf("输入方阵的阶数:");
 scanf("%d",&n);
 printf("输入方阵的数据(%d个):",n*n);
 for (i = 0;i <= n - 1;i++)
 {
    
    
  for (j = 0;j <= n - 1;j++)
  {
    
    
   scanf("%d",&a[i][j]);
  }
 }
 search(a,n);
}
void search(int(*p)[N], int n)
{
    
    
 int i, j,maxi=0,maxj=0,pd=0;
 for (i = 0;i <= n - 1;i++)
 {
    
    
  for (j = 0;j <= n - 1;j++)
  {
    
    
   if (p[i][j] > p[i][maxj])
   {
    
    
    maxi = i;
    maxj = j;
   }
  }
  for (i = 0;i <= n - 1;i++)
  {
    
    
   if (p[maxi][maxj] > p[i][maxj])
   {
    
    
    pd = 1;
    break;
   }
  }
  if (pd == 0)
  {
    
    
   printf("鞍点的行为:%d 列为:%d", maxi, maxj);
   break;
  }
 }
 if (pd != 0)
 {
    
    
  printf("NO");
 }
}  

4. Code output result

输入方阵的阶数:3
输入方阵的数据(9个):1 2 3 4 5 6 7 8 9
鞍点的行为:0 列为:2

Guess you like

Origin blog.csdn.net/weixin_48342617/article/details/109703671