Friday, March 21, 2014

Array with Method_Ex_5 (Wk 8) Feb 24-28, 2014

Q: Write method to return the highest values.

 static void Main(string[] args)
        {
            int[] A = { 12, -5, -9, 3, 6, 19, -13, -22, 33, 1, -17, 29 };

            int result = Maxvalue(A);
            Console.WriteLine("Maximum value is: {0}", result);

            Console.ReadLine();
        }
        static int Maxvalue (int [] A)
        {
            int Max = A[0];
            for (int i = 1; i < A.Length; i++)
            {
                if (Max < A[i])
                    Max = A[i];
            }
            return Max;
        }
    }
}

No comments:

Post a Comment