Question
void my_arrfn(int myarr[], int sz, int m){
int i;
for(i=0;i<sz;i++){
myarr[i] *= m;
} }
a)int anarr[4] = { 3, 4, 2, 5};
my_arrfn(anarr, 4, 3);
b)int anarr[4] = {5, 2, 2, 10};
my_arrfn(anarr, 4, 10);
2 . Write a function called “closest” (prototype given below) which takes 3 arguments: An array of integers (arr), the size of the array (sz), and an integer (q), and returns the index of the element in arr which is closest to q.
int closest(int arr[], int sz, int q)
For instance, if arr = [1,2,5,1], then closest(arr,4,6) should return 2 since arr[2] is closest to 6. The distances should be measured using the absolute value.
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
1.a) after the
int anarr[4] = { 3, 4, 2, 5};
my_arrfn(anarr, 4, 3);
is called
anarr = {9, 12, 6, 15}
b) after the
int anarr[4] = {5, 2, 2, 10};
my_arrfn(anarr, 4, 10);
is called
anarr = {50, 20, 20, 100}
The new value of the array member is the old value multiplied with m, which is 3 in a) and 10 in b) case....