Find Largest Element From an Integer Array in C#

Hi everyone do you know about Find Largest Element From an Integer Array in C#. With this article, you can clearly see everything you have in doubt.

Find Largest Element From an Integer Array in C#

Find Largest Element From an Integer Array in C#

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int i       = 0;
            int large   = 0;
			//array declaration
            int[] arr   = new int[5];
			
			//reading array elements 
            Console.WriteLine("Enter array elements : ");
            for (i = 0; i < arr.Length; i++)
            {
                Console.Write("Element[" + (i + 1) + "]: ");
                arr[i] = int.Parse(Console.ReadLine());
            }

            //assigning first element to the array
			large = arr[0];
			//loop to compare value of large with other elements
            for (i = 1; i < arr.Length; i++)
            {
				//if large is smaller than other element
				//assig that element to the large
                if (large < arr[i])
                    large = arr[i];
            }
			//finally, we will have largest element, printing here
            Console.WriteLine("Largest element in array : " + large);
        }
    }
}
Enter array elements :
Element[1]: 12
Element[2]: 13
Element[3]: 10
Element[4]: 25
Element[5]: 8
Largest element in array is : 25

Final Words

Through this article, we have come to know clearly that Find Largest Element From an Integer Array in C#. If you have any doubts please leave a comment via the comment box.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment