Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a C# console application that implements an int array. Use 2 \'for\' loo

ID: 3855461 • Letter: D

Question

Develop a C# console application that implements an int array. Use 2 'for' loops, the first to fill the array using the Random class to generate random integers (see p241, section 7.9) using the next method of the Random class and a second for loop to iterate through the filled array and print the values entered into the array by the random number generator. Use the array’s length variable to stay within the array bounds for both loops.

Possible output might look like this:

The array value is 488
The array value is 402
The array value is 237
The array value is 48
The array value is 390
The array value is 186
The array value is 425
The array value is 342
The array value is 477
The array value is 319
Press any key to continue . . .

Name the .cs file Assignment_6_yourlastname and submit it to the link below.

Explanation / Answer

using System.IO;
using System;

class Program
{
static void Main()
{
Random r = new Random();
int[] arr = new int[10];
for(int i=0;i<arr.Length; i++) {
arr[i] = r.Next(0,1000);
}
for(int i=0;i<arr.Length; i++) {
Console.WriteLine("The array value is "+arr[i]);
}
  
}
}

Output:

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

sh-4.3$ mono main.exe                                                                                                                                                                                

The array value is 102                                                                                                                                                                               

The array value is 917                                                                                                                                                                               

The array value is 132                                                                                                                                                                               

The array value is 973                                                                                                                                                                               

The array value is 85                                                                                                                                                                                

The array value is 394                                                                                                                                                                               

The array value is 888                                                                                                                                                                               

The array value is 607                                                                                                                                                                               

The array value is 300                                                                                                                                                                               

The array value is 848