 Functions in Programming Language C

Subject Computer Science C-Family Programming

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 = { ­3, 4, 2, ­5};
my_arrfn(anarr, 4, 3);
b)int anarr = {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 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 = { 3, 4, 2, 5};
my_arrfn(anarr, 4, 3);
is called
anarr = {9, 12, 6, 15}

b) after the
int anarr = {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

Related Homework Solutions

C++: Student Structure with Array and Pointer \$18.00
C++
Computer
Science
Student
Pointer
Array
Average
Dynamical
Programming
Structure
The Simplistic Primary Predictor in C++ \$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++ \$8.00
Computer Science
C++ Programming
OOP
Dynamic Arrays
Functions
Donations
Codes
Loops
Statements
Variables
Pointers
Memory Allocation
Users
Constants
Input
Output
Integers
A C++ Class That Will Manage an Encrypted Password \$48.00
C++
Computer
Science
C-Family
Programming
Class
Driver
Test
Conditions
Linux
Program For Retail Store Using C++ \$30.00
Programming
C++
Computer Science
Coding
Walmart
Amazon
Sales
Products
Prices
Structures
Orders
Arrays
CSV Files
Variables
Statements
Prototypes
Pointers
Grade Point Average (GPA) Calculator \$88.00
Name