We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, June 8, 2015


Find The Greatest And Smallest Number In Integer Array and find Difference between largest and smallest.


 class Program
    {
        static void Main(string[] args)
        {
            int n,largest, smallest;
            int[] a = new int[50];
            Console.WriteLine("Enter the size of Array");
            n = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Enter the array elements");
            for (int i = 0; i < n; i++)
            {
                a[i] = Int32.Parse(Console.ReadLine());
                Console.WriteLine();
            }
            Console.WriteLine("");
            largest = a[0];
            smallest = a[0];
            for (int i = 1; i < n; i++)
            {
                if (a[i] > largest)
                    largest = a[i];
                else if (a[i] < smallest)
                    smallest = a[i];
            }
            Console.WriteLine("Largest element in the array is {0}", largest);
            Console.WriteLine("Smallest element in the array is {0}", smallest);        
            Console.WriteLine("Difference: {0}",largest - smallest);
            Console.ReadLine();
        }
    }
OUTPUT:



No comments: