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 MessageBox 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 Display(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[] {1,2,3,4,5,6,7,8,9 };
double[] b = new double[] {5,6,7,8,9};
double[] c = new double[a.Length];
MessageBox.Display(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