找出一個二維陣列中的“鞍點”,即該位置上的元素在該行中 最大,在該列中最小(也可能沒有“鞍點”),列印有關資訊。(提示:注意特 殊情況:沒鞍點或多個鞍點)
#import <Foundation/Foundation.h>
#define ROW 3
#define COL 4
int main(int argc, constchar * argv[]) {
int a[ROW][COL];
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
a[i][j] = arc4random() % 50 ;
}
}
for (int i = 0; i < ROW; i++) {
for (int j = 0; j <
printf("%2d ",a[i][j]);
}
printf("\n");
}
int max = 0;
int c[3] ;
for (int i = 0; i < ROW; i++) {
max = a[i][0];
// printf("%d ",a[i][0]);
for (int j = 0; j < COL ; j ++) {
if(max <= a[i][j])
{
max = a[i][j];
c[i] = j;
}
} //printf("%d ",c[i]);
}
int count = 0;
for (int k = 0; k < 3; k++) {
int index = 0;
for (int i = 0; i < ROW ; i ++) {
if(a[k][c[k]] > a[i][c[k]])
index = 1;
}
if(index == 0)
{
printf("鞍點為:%d ",a[k][c[k]]);
count = 1;
}
}
if (count ==
printf("沒有鞍點!");
return0;
}