找寻鞍点
#include <stdio.h>
#include <stdlib.h>
#define m 4
#define n 5
/* 找寻鞍点 find the andian you can guess what */
int main(int argc, char *argv[]) {
int a[m][n];
int max,mj,flag;
int i,j,k;
printf("input the number :\n");
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
scanf("%d",&a[i][j]);// input of the array
}
}
for(i=0;i<m;++i)
{
max=a[i][0];
mj=0;
for(j=0;j<n;j++)
{
if(a[i][j]>max)
{
max=a[i][j];
mj=j;
}
}
printf("第%d行的最大数为%d,其在第%d列\n",i,max,mj);// the largest number in the row
flag=1; // before the whole line 's circulation . and the second row can inherit the row 's flag value
//so every thing have done ,you finally can get a utimate flag value , which can be used to judge weather the
// andian is exist. ^-^
for(k=0;k<m;k++)
{
if(a[k][mj]<max)
{
//printf("a[%d][%d]=%d\n",k,mj,a[k][mj]);
flag=0;
continue;
}
}
if(flag)
{
printf("andian is a[%d][%d]=%d\n",i,mj,max);
break;
}
}
if(!flag)
{
printf("it's not exist\n");
}
return 0;
#include <stdlib.h>
#define m 4
#define n 5
/* 找寻鞍点 find the andian you can guess what */
int main(int argc, char *argv[]) {
int a[m][n];
int max,mj,flag;
int i,j,k;
printf("input the number :\n");
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
{
scanf("%d",&a[i][j]);// input of the array
}
}
for(i=0;i<m;++i)
{
max=a[i][0];
mj=0;
for(j=0;j<n;j++)
{
if(a[i][j]>max)
{
max=a[i][j];
mj=j;
}
}
printf("第%d行的最大数为%d,其在第%d列\n",i,max,mj);// the largest number in the row
flag=1; // before the whole line 's circulation . and the second row can inherit the row 's flag value
//so every thing have done ,you finally can get a utimate flag value , which can be used to judge weather the
// andian is exist. ^-^
for(k=0;k<m;k++)
{
if(a[k][mj]<max)
{
//printf("a[%d][%d]=%d\n",k,mj,a[k][mj]);
flag=0;
continue;
}
}
if(flag)
{
printf("andian is a[%d][%d]=%d\n",i,mj,max);
break;
}
}
if(!flag)
{
printf("it's not exist\n");
}
return 0;
}