Write a program that generates an array of 20 random integers, each in the range -15 to 15, and prints
Write a program that generates an array of 20 random integers, each in the range -15 to 15, and prints the original and then only the negative elements of the array to the screen
C # language
Random rand = new Random (); // declaring an instance of the Random class
int [] array = new int [20]; // create an array of 20 elements
for (int i = 0; i <array.Length; i ++)
{
array [i] = rand.Next (-15,15); // fill the array with numbers from -15 to 15
}
int counter = 0; // variable counter
for (int i = 0; i <array.Length; i ++)
{
Console.Write (array [i] + “”); // display the original elements of the array
}
Console.WriteLine ();
for (int i = 0; i <array.Length; i ++)
{
if (array [i] <0)
{
Console.Write (array [i] + “”); // display negative elements
}
}
Console.ReadLine (); // read from the console, otherwise it will close