Home

Tuesday, 19 July 2016

Find Max value within Matrix using C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArrayMax
{
    class Program
    {
         int mvalue = 0;
        int[,] array = { { 3, 7, 8 }, { 17, 32, 1 }, { 32, 45, 7 } };
        public int max(int[,] array)
        {

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (i == 0)
                        mvalue= array[0, 0];
                    else
                    {
                        if (array[i, j] > mvalue)
                            mvalue = array[i, j];
                    }
                }
            }
            return 0;
        }
       static void Main()
       {
            Program p = new Program();
            p.max(p.array);
            Console.WriteLine("Max Value: {0}", p.mvalue);
            Console.ReadLine();
        }

    }
}

No comments:

Post a Comment