Question

1. Below a function my_arrfn is defined. Show the contents of the array anarr after each call to my_arrfn with the given array
    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....

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

The Simplistic Primary Predictor in C++
Homework Solution
$20.00
Computer Science
Programming
C++
Primary Predictor
Election Results
Factors
Candidates
States
Information
Commercials
Campaign
Calculations
Statements
Variables
Input
Output
Dynamic Arrays in C++
Homework Solution
$8.00
Computer Science
C++ Programming
OOP
Dynamic Arrays
Functions
Donations
Codes
Loops
Statements
Variables
Pointers
Memory Allocation
Users
Constants
Input
Output
Integers
Program For Retail Store Using C++
Homework Solution
$30.00
Programming
C++
Computer Science
Coding
Walmart
Amazon
Sales
Business
Products
Prices
Structures
Orders
Arrays
CSV Files
Variables
Statements
Prototypes
Pointers
Get help from a qualified tutor
Live Chats