Answer to Question #330107 in C# for Bunny

Question #330107

Create a program that asks the user to input 5 numbers. The numbers should be stored in a list, after which, your program should determine the lowest number on the list using a loop then it will display the lowest number. Comment your code below. Sample Output: Enter 5 numbers: 6 3 2 1 4 Lowest Number is 1

1
Expert's answer
2022-04-18T08:40:26-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace C_SHARP
{
    class Program
    {


        static void Main(string[] args)
        {
            List<int> numbers = new List<int>();
            Console.Write("Enter 5 numbers: ");
            string[]numbersStr= Console.ReadLine().Split(' ');
            for (int i = 0; i < 5; i++)
            {
                numbers.Add(int.Parse(numbersStr[i]));
            }
            int minNumber = numbers[0];
            for (int i = 0; i < numbers.Count; i++)
            {
                if (numbers[i] < minNumber)
                {
                    minNumber = numbers[i];
                }
            }
            Console.WriteLine("Lowest Number is {0} ", minNumber);


            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