Using List in C#. Write a program that can input 5 numbers then list in sorted form then after, insert another one number.
using System;
using System.Collections.Generic;
namespace App
{
class Program
{
static void Main(string[] args)
{
List<int> numbers = new List<int>();
for (int i = 0; i < 5; i++)
{
Console.Write("Enter number {0}: ",(i+1));
numbers.Add(int.Parse(Console.ReadLine()));
}
numbers.Sort();
Console.WriteLine("Sorted numbers:");
for (int i = 0; i < numbers.Count; i++)
{
Console.Write("{0} ",numbers[i]);
}
Console.Write("\nEnter another one number: ");
numbers.Add(int.Parse(Console.ReadLine()));
Console.WriteLine("\nAll numbers:");
for (int i = 0; i < numbers.Count; i++)
{
Console.Write("{0} ", numbers[i]);
}
Console.ReadLine();
}
}
}
Comments
Leave a comment