Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

How to find the biggest element in a matrix within a class with C#

1 Answer

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        int[,] arr;
        int ub0, ub1;

        Program()
        {
            arr = new int[,] { { 7, 1, 98 }, { 100, 21, 3 } };
            ub0 = arr.GetLength(0);
            ub1 = arr.GetLength(1);
        }

        void PrintArray()
        {
            for (int i = 0; i < ub0; i++)
            {
                for (int j = 0; j < ub1; j++)
                    Console.Write(arr[i, j] + " ");

                Console.WriteLine("\n");
            }
        }

        int BiggestElement()
        {
            int biggest = arr[0, 0];

            for (int i = 0; i < ub0; i++)
            {
                for (int j = 0; j < ub0; j++)
                {
                    if (biggest < arr[i, j])
                        biggest = arr[i, j];
                }
            }

            return biggest;
        }

        static void Main(string[] args)
        {
            Program obj = new Program();

            obj.PrintArray();

            Console.WriteLine("Biggest Element is : {0}", obj.BiggestElement());
        }
    }
}

/*
run:
     
7 1 98

100 21 3

Biggest Element is : 100
 
        
*/

 



answered May 14, 2017 by avibootz

Related questions

...