63 033
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #2551 in C# for ch azan

Question #2551
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
Expert's answer
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!

Comments

Assignment Expert
15.06.11, 19:44

You& are welcome!

azan Ch
24.05.11, 13:54

This Website is Really a great . . . . . Amazing

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions