Using C# do the following: - Declare three arrays of type double and of the same
ID: 645727 • Letter: U
Question
Using C# do the following:
- Declare three arrays of type double and of the same size. Initialize two of the arrays with values.
First Array Values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Second Array Values: 22, 32, 14, 54, 23, 71, 234, 63, 91, 11
- Write a method that takes the two arrays as arguments. The method finds the product of the two arrays and assigns it to the third array and the method returns the third array.
- Write a method that takes all the three arrays as parameters and displays the output on your console window.
- Display your output on a MessageBox dialog
Explanation / Answer
using System.IO;
using System;
class Program
{
public int Mul(int[] arr1, int[] arr2)
{
int[] result = new int[5];
for (int i = 0; i < arr1.Length; i++ )
{
result[i]=arr1[i]*arr2[i];
}
return result;
}
public void print(int[] arr1, int[] arr2, int[] arr3)
{
for (int i = 0; i < arr1.Length; i++ )
{
Console.WriteLine("element: {0}",arr1[i]);
}
for (int i = 0; i < arr2.Length; i++ )
{
Console.WriteLine("element: {0}",arr2[i]);
}
for (int i = 0; i < arr3.Length; i++ )
{
Console.WriteLine("element: {0}",arr3[i]);
}
}
static void Main(string[] args)
{
int [] first = new int[] { 99, 98, 92, 97, 95};
int [] second = new int[] { 99, 98, 92, 97, 95};
Program n = new Program();
int[] third = n.Mul(first, second);
n.print(first,second,third);
Console.ReadLine();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.