forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaddlepoint.cpp
54 lines (39 loc) · 1.02 KB
/
saddlepoint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// C++ program to find Saddle point in a matrix
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
bool findSaddlePoint(int mat[MAX][MAX], int n)
{
for (int i = 0; i < n; i++)
{
int min_row = mat[i][0], col_ind = 0;
for (int j = 1; j < n; j++)
{
if (min_row > mat[i][j])
{
min_row = mat[i][j];
col_ind = j;
}
}
int k;
for (k = 0; k < n; k++)
if (min_row < mat[k][col_ind])
break;
if (k == n)
{
cout << "Value of Saddle Point " << min_row;
return true;
}
}
return false;
}
int main()
{
int mat[MAX][MAX] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int n = 3;
if (findSaddlePoint(mat, n) == false)
cout << "No Saddle Point ";
return 0;
}