Design a program that has a two-dimensional integer array with 7 rows and 7 columns. The program should store a random number in each element. Then, the program should search the array for saddle points. A saddle point is an element whose value is less than or equal to all the other values in the same row, and greater than or equal to all the other values in the same column.

Respuesta :

Answer:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int saddle_Point_Value(int n, int arr[n][n])

{

int row, col = 0;

int k;

for (int i = 0; i < n; i++) {

    row = arr[i][0]

    col = 0;

    for (int j = 1; j < n; j++) {

        if (row > arr[i][j]) {

            row = arr[i][j];

            col = j;

        }

    }

    for (k = 0; k < n; k++) {

       if (row < arr[k][col])

           break;

    }

    if (k == n) {

        printf("\nThe saddle point value is : [%d]\n", row);

        return 1;

    }

  }

  return 0;

}

int main()

(

   int n = 7

   int arr[n][n];          //Declaring 7 x 7 array

   int i, j;

   //Creating random numbers

   for (i = 0; i < n; i++) {

      for (j = 0; j < n; j++) {

         arr[i][j] = rand()%50; //Random numbers up to...

      }

   }

   printf("\n Array elements :\n ");

   for (i = 0; i < n; i++) {

      for (j = 0; j < n; j++) {

         print("%d\t", arr[i][j]);

      }

      print("\n");

   }

   if (!(saddle_Point_Value(n, arr)))

        printf('No Saddle Point.!!\n");

   return 0;

}

Explanation:

A properly functioning and running code is written in the answer. Just follow the steps.

Q&A Education