Define a console-program to create an array of integers. Initialize the array and assign the values in array. Define a method to pass the array and modify array elements. Display array elements by using for-each loop
using System;
namespace Array
{
class Program
{
& const int size = 20;
& static private int[] array = new int[size];
& // The function that modifies the array
& static void ModifyArray()
& {
for (int i = 0; i < size; i++)
array[i] -= 30; & // Modifying the array
& }
& static void Main(string[] args)
& {
Random random = new Random();
// Initialization of the array
for (int i = 0; i < size; i++)
array[i] = random.Next(50);
// Printing the array before modifying
Console.WriteLine("Now array is: ");
foreach (int number in array)
Console.Write("{0}, ", number);
// Modifying the array
ModifyArray();
// Printing the array after modifying
Console.WriteLine("\n\nThe array after modifying: ");
foreach (int number in array)
Console.Write("{0}, ", number);
Console.Write("\n\nPress Enter to exit");
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!
Learn more about our help with Assignments:
C#