jeudi 18 juillet 2019

How to generate five sets of random number in c#

I am trying to generate five sets of a random number in c# order by highest number and comma-separated

I tried using

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
            //Console.WriteLine("Hello, world!");
            int[] randNumber = new int[5];
            Random rand = new Random();
            Console.Write("The random numbers are: "); 
           for (int h = 0; h < randNumber.Length; h++)
           {
            randNumber[h] = rand.Next(1, 20);           
           }

           Console.Write(string.Join(", ", randNumber));

        }
    }
}

I am getting output only of one set without sorting(Highest to lowest) i.e.

The random numbers are: 12, 2, 12, 19, 11

The Expected Output should be like this::

  1. 11,9,7,6,4
  2. 13,8,7,6,4
  3. 13,9,7,6,2
  4. 17.9,7,6,1
  5. 1,6,7,4,14



Aucun commentaire:

Enregistrer un commentaire