Question: Program to find the largest element in the matrix.
To find the largest element of the matrix we simply take a variable temp and store the remporary value of matrix in it anf aftert every comparison we change them accourding to given condition.
First of all take a matrix, declare the order of matrix and after that enter the element in the matrix after that do the operation to find out the largest element in the matrix
Code Snippet:
- using System;
- public class LarEle
- {
- public static void Main()
- {
- int[,] matA = new int[10,10];
- int i, j, row, col;
- Console.Write("\nEnter the no. of row: ");
- i=Convert.ToInt16(Console.ReadLine());
- Console.Write("Enter the no. of col: ");
- j=Convert.ToInt16(Console.ReadLine());
- Console.WriteLine("\nEnter the element in Matrix: ");
- for(row=0; row<i; row++)
- {
- for(col=0; col<j; col++)
- matA[row,col]=Convert.ToInt32(Console.ReadLine());
- Console.WriteLine();
- }
- Console.WriteLine("\nMatrix A: ");
- for(row=0; row<i; row++)
- {
- for(col=0; col<j; col++)
- Console.Write(" {0}", matA[row,col]);
- Console.WriteLine();
- }
- int big = matA[0,0];
- for(row=0; row<i; row++)
- {
- for(col=0; col<j; col++)
- if(big < matA[row,col])
- big=matA[row,col];
- }
- Console.Write("\nLargest element in matrix A is: {0}", big);
- Console.ReadLine();
- }
- }