39) Write a program to find the saddle point of a given matrix in C++.
In this we are going to see  a program to calculate saddle point of matrix in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <conio.h>
void main()
{
    clrscr();
    int i, j, c, min, x, z;
    int num[3][3];
    cout << "Enter the elements of the 3x3 matrix:" << endl;
    for (i = 0; i < 3; i++)
    {
        for (j = 0; j < 3; j++)
        {
            cin >> num[i][j];
        }
    }
    for (i = 0; i < 3; i++)
    {
        min = num[i][0];
        x = 0;
        for (c = 1; c < 3; c++)
        {
            if (min > num[i][c])
            {
                min = num[i][c];
                x = c;
            }
        }
        z = 0;
        for (j = 0; j < 3; j++)
        {
            if (min > num[j][x] || min == num[j][x])
            {
                z = z + 1;
            }
        }
        if (z == 3)
        {
            cout << "The saddle point is " << min;
        }
    }
    getch();
}

The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;
int main()
{
    int i, j, c, min, n, x, z;
    cout << "Enter the order of the matrix: ";
    cin >> n;
    int num[n][n];
    cout << "Enter the elements of the matrix:" << endl;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
            cin >> num[i][j];
    }
    for (i = 0; i < n; i++)
    {
        min = num[i][0];
        x = 0;
        for (c = 1; c < n; c++)
        {
            if (min > num[i][c])
            {
                min = num[i][c];
                x = c;
            }
        }
        z = 0;
        for (j = 0; j < n; j++)
        {
            if (min > num[j][x] || min == num[j][x])
                z = z + 1;
        }
        if (z == n)
            cout << "The saddle point is " << min;
    }
    return 0;
}



#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post