Home > Back-end >  Multiple values inside array
Multiple values inside array

Time:09-21

How do I multiple my array1 to array2 in backward? and then multiple its product to array3 in backward also

for example: array1 = { 2, 4, 6, 8, 10, 12, 14, 16 } * array2 = { 1, 2, 3, 4, 5, 6, 7, 8 } expected output is {2, 8, 18, 32, 50, 72, 128} and how do I multiple this expected output to my array 3?

I only know how to store and display values inside my array so far here is my code:

            int[] array1 = { 2, 4, 6, 8, 10, 12, 14, 16 };
            Console.Write("\nArray 1: ");
            Console.WriteLine(String.Join(", ", array1));

            int[] array2 = { 8, 7, 6, 5, 4, 3, 2, 1 };
            Console.Write("\nArray 2: ");
            Console.WriteLine(String.Join(", ", array2));


            int[] array3 = { 3, 4, 3, 0, 1, 7, 4, 2 };
            Console.Write("\nArray 3: ");
            Console.WriteLine(String.Join(", ", array3));

            Console.Read();

CodePudding user response:

Console.WriteLine(string.Join(",", ));

or

array3 = array2.Reverse().Zip(array1, (a, b) => a*b).ToArray();
  • Related