Find min and max number in a given array

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

namespace ConsoleApplication1
{
    class Program
    {
        public static void Main()
        {
            int number; //number
            float large, small;
            int[] a = new int[50];
            Console.WriteLine("Enter the size of Array");
            number  = Int32.Parse( Console.ReadLine());          
            Console.WriteLine("Enter the array elements");
            for (int i = 0; i < number; i++)
            {
                a[i] = Int32.Parse(Console.ReadLine());
             
            }
            Console.Write("");
            large = a[0];
            small = a[0];
            for (int i = 1; i < number; i++)
            {
                if (a[i] > large)
                    large = a[i];
                else if (a[i] < small)
                    small = a[i];
            }
            Console.WriteLine("Largest element in the array is {0}", large);
            Console.WriteLine("Smallest element in the array is {0}", small);
            Console.Read();
        }
    }
}

Comments

Popular posts from this blog

Prime Number Program in C#

Fibonacci Series in C#

view in sql server