This is my first question, so I hope I explain this correctly ;-)
I need to create a method that takes in a double array, numbers, and returns a new array containing the square of each element in numbers. (Any help and guidance will be greatly appreciated. Thank you!)
The parameters I have been given are as follows:
<param name="numbers">Input array</param>
<returns>double array</returns>
public double[] PowerArray(double[] numbers)
This is what I've written so far, but it returns double numbers. I need the return to contain decimal numbers.
{
double[] PowerArray = Array.ConvertAll(numbers, i => i * i);
return PowerArray;
}
My instructions are to return my answers following this example: double[] input = { -2.2, 0, 1.1, 3 } should return double[] [4.84, 0, 1.21. 9]. My return is giving me double[] [4.840000000000001, 0, 1.2100000000000002, 9].