0

How to write a program that multiplies 2 arrays in C

a program that multiplies two arrays, and are multiplied on an element-by-elemnt basis... so like [4,2,7]*[3,5,8]=[12,10,56]. All i know is that it needs to have void multiply(int arr1[], int n, int arr2[], int arr3[]; Example: Enter the length of the array: 5 Enter the elements of the first array: 3 4 7 14 9 Enter the elements of the 2nd array: 12 8 2 5 3 Output: 36 32 14 70 27

11th Sep 2018, 10:50 PM
Jestboy
2 Answers
+ 5
int sizeOfArr = 5; int arr1[sizeOfArr] = {1, 2, 3, 4, 5}, arr2[sizeOfArr] = {6, 7, 8, 9, 10}, mulArr[sizeOfArr] = {0}; for (int i = 0; i < sizeOfArr; i++) mulArr[i] = arr1[i] * arr2[i]; Print it yourself
12th Sep 2018, 7:27 AM
blACk sh4d0w
blACk sh4d0w - avatar
0
Jestboy ask for input which is length of array using scanf and store the same in variable n for example... declare three array pointer referring to n size array one for output and two for input.. for example, int* arrOutput = new int[n] loop through n numbers and store them in array twice loop through n number in a loop and multiply elements of same index from both array to output array
12th Sep 2018, 12:57 AM
Ketan Lalcheta
Ketan Lalcheta - avatar