Question: The C# program below performs the following operations: (1) define and initialize a 1d array, the data type of which is double. It has 8
The C# program below performs the following operations: (1) define and initialize a 1d array, the data type of which is double. It has 8 elements. (2) use a for loop to print the value of each element. (3) calculate the sum of all elements of the array and then print its value. (4) calculate the average of all elements of the array and then print its value. (5) find the max element of the array and then print its value. double[] myList = new double[8]{1.9, 2.9, 3.4, 4.3, 5.7, 6.1, 7.9, 8.4}; double average = 0; // Print all the array elements for (int i = 0; i < myList.Length; i++) { Console.WriteLine("{0}", myList[i]); }
// Summing all elements double total = 0; for (int i = 0; i < myList.Length; i++) { total += myList[i]; } Console.WriteLine("Total is {0}", total);
average = total/myList.Length; Console.WriteLine("Average is {0}", average);
// Finding the largest element double max = myList[0]; for (int i = 1; i < myList.Length; i++) { if (myList[i] > max) max = myList[i]; } Console.WriteLine("Max is {0}", max); Console.ReadKey(); }
3. Write a program in PHP that performs the same operations. (25 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
