Ms. Seena has brought 10 items and she wants to print the item with minimum and maximum cost. Write a software program to do it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal[] itemCosts = new decimal[10];
            int iMax=0, iMin = 0;
            decimal max = -999, min = 999;
            Random r = new Random();
            for (int i = 0; i < itemCosts.Length; i++)
            {
                itemCosts[i] = r.Next(10, 150);
            }
            for (int i = 0; i < itemCosts.Length; i++)
            {
                if (itemCosts[i] > max)
                {
                    max = itemCosts[i];
                    iMax = i;
                }
                if (itemCosts[i] < min)
                {
                    min = itemCosts[i];
                    iMin = i;
                }
            }
            Console.WriteLine("Max cost item: {0}", itemCosts[iMax]);
            Console.WriteLine("Min cost item: {0}", itemCosts[iMin]);
            Console.ReadKey();
        }
    }
}
 
Comments