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
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();
}
}
}
Comments
Leave a comment