Answer to Question #336350 in C# for SITHEMBELE

Question #336350

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.

1
Expert's answer
2022-05-02T13:37:08-0400
    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];
                }
            }
        }
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS