Answer to Question #269323 in C# for Bully

Question #269323

Using List in C#. Write a program that can input 5 numbers then list in sorted form then after, insert another one number.


1
Expert's answer
2021-11-20T14:20:26-0500
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();
        }
    }
}



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