Create a function mult_arr which accepts two pointers-to-double as input along with an integer reflecting the length of each array. The function should return void. Using pointer arithmetic to access the array elements, compute the element-wise product of the two arrays in-place (the result is stored in the first array). The function should return void. In main, read in two arrays of 10 values from the user following the I/O format seen in the example run below. On a new line, print the output following the format shown below. Save your code as prob2.c.
Example Run
> 1 1 1 1 1 1 1 1 1 1
> 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2
Code:
#include <stdio.h>
void mult_arr(int *a,int *b,int n)
{
int i;
for(i=0;i<n;i++)
{
*(a+i)=*(a+i)**(b+i);
}
}
int main()
{
int i,a[10],b[10];
printf("Read arry A:");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
printf("Read arry B:");
for(i=0;i<10;i++)
{
scanf("%d",&b[i]);
}
mult_arr(a,b,10);
printf("Multiplication array:");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
return 0;
}
Screenshots:
Get Answers For Free
Most questions answered within 1 hours.