NET AND C ASSIGNMENT Two integer numbers to serve as the low

(NET AND C# ASSIGNMENT)

Two integer numbers to serve as the lower bound and upper bound for a range of random numbers. A list of integer numbers within the above range of random numbers to be excluded from the generated random numbers.
The lower bound, upper bound as well as the list of exceluded numbers will be passed to method GenerateSpecialRandom which will generate 50 valid random numbers and return them to the Main method using an out array parameter. Main method will take the random numbers and output them – separated with commas (,) on the console.
Hint: method GenerateSpecialRandom would need to have a variable number of arguments. (i.e., by using params int[]

validNumbers )

Solution

using System.IO;
using System;

class Program
{
static void Main()
{
Console.WriteLine(\"Enter the lower bound: \");
int lower=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(\"Enter the upper bound: \");
int upper=Convert.ToInt32(Console.ReadLine());
int[] randNum = GenerateSpecialRandom(lower, upper);
foreach(int j in randNum){
Console.Write(j+\", \");
}
Console.WriteLine();
  
}
static int[] GenerateSpecialRandom (int lower, int upper){
Random r = new Random();
int[] randNum = new int[50];
  
for(int i=0; i<randNum.Length; i++){
randNum[i] = r.Next(lower+1, upper);
}
return randNum;
}
}

Output:

sh-4.3$ mcs *.cs -out:main.exe                                                                                                                                                                                                                         

sh-4.3$ mono main.exe                                                                                                                                                                                                                                  

Enter the lower bound:                                                                                                                                                                                                                                 

1                                                                                                                                                                                                                                                      

Enter the upper bound:                                                                                                                                                                                                                                 

100                                                                                                                                                                                                                                                    

85, 20, 26, 40, 86, 87, 4, 54, 9, 80, 38, 63, 77, 82, 10, 54, 7, 65, 19, 31, 44, 77, 91, 5, 67, 56, 31, 62, 15, 49, 16, 7, 71, 78, 26, 14, 79, 88, 80, 37, 80, 15, 16, 53, 74, 53, 29, 82, 83, 90

(NET AND C# ASSIGNMENT) Two integer numbers to serve as the lower bound and upper bound for a range of random numbers. A list of integer numbers within the abov
(NET AND C# ASSIGNMENT) Two integer numbers to serve as the lower bound and upper bound for a range of random numbers. A list of integer numbers within the abov

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site