C语言求鞍点

#include<stdio.h>

void main()

{

int a[3][3],max,t,count;

    bool flag=false;

printf("请输入3*3数组的数值:\n");

for(int i=0;i<3;i++)

for(int j=0;j<3;j++)

scanf("%d",&a[i][j]);

 

for( i=0;i<3;i++)         

{

count=0;                       //用于判定是否符合条件

for(int j=0;j<3;j++)

{

if((j+1)<3)                  //注意数组不要越界

{

if(a[i][j]<a[i][j+1])    //选择某一行中最大值。

{                          并记录所在列位置t

    max=a[i][j+1];

    t=j+1;

}

    else

{

    max=a[i][j];

    t=j;

}

}

}

for(int z=0;z<3;z++)

if(max>a[z][t])              //判定该行最大值是否

{                              在该列下最小,列数为t,

count++;                   (t为刚才记录的列位置)

}                              如果不是列最小值,count++

if(count==0)                 //如果count为0,说明存在鞍点。

{

flag=true;

printf("该数组鞍点在第%d行,为:",i);

printf("%d\n",max);

}

}

if(!flag)

  printf("无鞍点");

}

posted @ 2013-12-12 19:15  Latent_Truth  阅读(2718)  评论(0编辑  收藏  举报