Thursday, July 18, 2013

Find Maximum value of an Array without Using Predefined Method in C#.Net?

In this article i would like to present Find Maximum value of an Array without Using Predefined Method.In Previous Article i would like to publish How To Find the Largest Number using Arrays in c#.Net?

                Array can be defined as a collection of similar dataitems.In C#.Net array act as a ReferenceType.We can access the elements of an array using index values.


                    DataType[] NameOf The Array=new DataType[size];

                   int[] a=new int[5];
                   int[] a=new int[]{12,10,1,3,5};
  1. If we Declare the size of the array it can take exactly that size number of values.
  2. If we are not declare the size of the array then we can accommodate n number of values.

using System;

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

namespace arr
    class Class1
        static void Main(string[] args)
            int size,max,loc=1;
            Console.WriteLine("Enter the Number of Elements In an Array");
            size = Convert.ToInt32(Console.ReadLine());
            int[] a=new int[size];          
            Console.WriteLine("Enter the Elements Of The Array");
            for (int i = 0; i < a.Length; i++)
                a[i] = Convert.ToInt32(Console.ReadLine());
            max = a[0];
            for (int j = 0; j < a.Length; j++)
                if (a[j] > max)
                    max = a[j];
                    loc = j + 1;
            Console.WriteLine("maximum Element Present at location {0} and its value is {1}",loc,max);


Maximum Element Of Array Without Using Predefined Functions in C#

No comments: