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
1
Expert's answer
2011-05-23T10:08:38-0400
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(); & } } }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
You& are welcome!
This Website is Really a great . . . . . Amazing
Leave a comment