Answer to Question #336612 in C# for SITHEMBELE

Question #336612

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.


1
Expert's answer
2022-05-03T14:19:12-0400
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];
                }
            }
        }
    }

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