Array To find Maximum Number using C#

How to find Number is minimum and maximum using array

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

namespace array_maximum
{
    class Program
    {
        static void Main(string[] args)
        {
            int d;
            int n;
            float large, small;
            int[] x= new int[40];
            Console.WriteLine("Enter the size of the Array");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the array elements");
            for (int i = 0; i < n; i++)
            {
            
                 x[i]= int.Parse(Console.ReadLine());
            }
            Console.Write("");
            large = x[0];
            small = x[0];
            for (int i = 1; i < n; i++)
            {
                if (x[i] > large)
                    large = x[i];
                else if (x[i] < small)
                    small = x[i];
            }
            Console.WriteLine("Large element in array  {0}", large);
            Console.WriteLine("Small element in  array {0}", small);
        }
    }
}

OutPut : 

Previous
Next Post »