C# Program to find saddle point in a matrix


In this program, You will learn how to find saddle point in a matrix in C#.


2 3 4

5 6 7

8 9 10

Value of Saddle Point: 8

Example: How to find saddle point in a matrix in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int i, j, num, sm, p, larg, f = 1;
		int[,] a = new int[10, 10];

		Console.Write("Enter size of an matrix:");
		num = Convert.ToInt32(Console.ReadLine());

		Console.Write("Enter 2D array elements:");
		for (i = 0; i < num; i++)
		{
			for (j = 0; j < num; j++)
			{
				a[i, j] = Convert.ToInt32(Console.ReadLine());
			}
		}

		Console.Write("\n2D Array List is :\n\n");
		for (i = 0; i < num; i++)
		{
			for (j = 0; j < num; j++)
			{
				Console.Write(a[i, j] + " ");
			}
			Console.WriteLine();
		}

		/* Logic start from here */
		for (i = 0; i < num; i++)
		{
			p = 0;
			sm = a[i, 0];
			for (j = 0; j < num; j++)
			{
				if (sm >= a[i, j])
				{
					sm = a[i, j];
					p = j;
				}
			}
			larg = 0;
			for (j = 0; j < num; j++)
			{
				if (larg < a[j, p])
				{
					larg = a[j, p];
				}
			}
			if (sm == larg)
			{
				Console.WriteLine("\nValue of Saddle Point :" + sm);
				f = 0;
			}
		}

		if (f > 0)
		{
			Console.WriteLine("\nNo Saddle Point ");
		}
	}
}

Output:

Enter size of an matrix:3
Enter 2D array elements:1
2
3
4
5
6
7
8
9

2D Array List is :

1 2 3 
4 5 6 
7 8 9 

Value of Saddle Point :7

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.