查找鞍点

/*win-tc*/
#include"stdio.h"
#include"conio.h"
#define MAXSIZE 20
void saddle(int A[MAXSIZE][MAXSIZE],int m,int n)  /*查找鞍点的函数*/
{
    int i,j,min,k,h,p;
    h=0;
    for(i=0;i    {
      min=A[i][0];
      for(j=1;j        if(A[i][j]            min=A[i][j];      /*查找每一行中最小的数*/
      for(j=0;j        if(A[i][j]==min)
        {
            k=j;
            p=0;
            while(p                p++;
            if(p>=m)
            {
                h++;     /*统计鞍点的个数*/
                printf("%d: %d,%d,%d",h,i,k,min);
            }
        }  
    }
    if(h==0)            /*没有找到鞍点时输出*/
        printf("cannot find the an'dian number!");
}

main()
{
    int m,i,k;
    int n;
    int A[MAXSIZE][MAXSIZE];
    void saddle(int A[][],int m,int n);
    printf("please input the array's row number m(m<=20):/n");
    scanf("%d",&m);                  /*输入数组的行*/
    printf("please input the array's col number n(n<=20):/n");
    scanf("%d",&n);                  /*输入数组的列*/
    printf("please input the array A[%d][%d] number(%d):/n",m,n,m*n);
    for(i=0;i        for(k=0;k            scanf("%d",&A[i][k]);
    printf("the array is:/n");
    for(i=0;i    {
        printf("A[%d]:/t",i);
        for(k=0;k            printf("%d/t",A[i][k]);
        printf("/n");
     }
     printf("the an'dian number is:/n");
     saddle(A,m,n);
     getch();
}
结果如下:

        (图一:没有找到鞍点)查找鞍点_第1张图片
          (图二:找到一个鞍点)

你可能感兴趣的:(程序设计)