194k views
1 vote
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.

User Loukaswho
by
5.8k points

1 Answer

5 votes

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("\\The saddle point value is : [%d]\\", 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("\\ Array elements :\\ ");

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

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

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

}

print("\\");

}

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

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

return 0;

}

Step-by-step explanation:

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

User Gugan Mohan
by
5.6k points