Create three arrays of type double. Do a compile-time initialization and place different values in two of the arrays. Write a program to store the product of the two arrays in the third array. Produce a display using the Message Box class that shows the contents of all three arrays using a single line for an element from all three arrays. For an added challenge, design your solution so that the two original arrays have a different number of elements. Use 1 as the multiplier when you produce the third array.
internal class Program
{
class MessageBox
{
public static void DisplayArrays(double[] a, double[] b, double[] c)
{
Product(a, b, c);
string arrays = "";
arrays += "Array a:";
for (int i = 0; i < a.Length; i++)
arrays += $" {a[i]} ";
arrays += "\n";
arrays += "Array b:";
for (int i = 0; i < b.Length; i++)
arrays += $" {b[i]} ";
arrays += "\n";
arrays += "Array c:";
for (int i = 0; i < c.Length; i++)
arrays += $" {c[i]} ";
Console.WriteLine(arrays);
}
}
static void Main(string[] args)
{
double[] a = new double[] { 20, 32, 53, 42, 13, 2, 7, 6, 9 };
double[] b = new double[] { 3, 8, 10, 1, 4 };
double[] c = new double[a.Length];
MessageBox.DisplayArrays(a, b, c);
Console.ReadKey();
}
static void Product(double[] a, double[] b, double[] c)
{
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < b.Length; j++)
{
c[i] += a[i] * b[j];
}
}
}
}
Comments
Leave a comment