Answer to Question #294229 in C# for Pacan

Question #294229

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. 


1
Expert's answer
2022-02-05T06:01:25-0500
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();
        }
    }
}

 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS