Welcome back to my blog,
We have been talking about Arrays in regards to C programing language for past few days. We will move on with our learning and today we will learn to multiply two arrays to create a third Arrays.
Let us look at the code.
You can copy the program from below :
#include <stdio.h>
int main() {
int array1[5] = {1, 2, 3, 4, 5};
int array2[5] = {6, 7, 8, 9, 10};
int result[5];
for (int i = 0; i < 5; i++) {
result[i] = array1[i] * array2[i];
}
printf("The multiplied array is: \n");
for (int i = 0; i < 5; i++) {
printf("%d\n", result[i]);
}
return 0;
}
Explanation of the above program
In this program, two arrays, array1 and array2, are defined with values. The program then uses a for loop to iterate through each element of the two arrays and multiply them together, storing the result in a new array called "result." The program then prints out the "result" array.
It's worth noting that this program assumes that both arrays have the same number of elements. If the arrays have different lengths, the program will need to be modified to handle that scenario.
Also, this program is only for the multiplication of two arrays of same size, you can modify it for the different size of arrays.
Output of the above program
It's the multiplication of each element of the two arrays, array1 and array2.
It is not at all difficult and just with the change of operator we are able to perform every mathematical logic into the Array.
If you also want to learn coding then find your teacher according to your language. For me i am comfortable with hindi language and follow hindi teachers.
You can refer to my teacher below in case you are also comfortable with hindi.
I will soon call myself a trader and a small programmer together.
Happy trading and keep learning what you love.