Modify selectionsortc so that it includes the following


Modify selection_sort.c so that it includes the following functions:

void selection_sort(int *a, int n);
int *find_largest(int *a, int n);
void swap(int *p, int *q);

selection_sort function: it should call find_largest function and swap function.

find_largest function: when passed an array of length n, the function will return a pointer to the array's largest element. The function should use pointer arithmetic - not subscripting - to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.

swap function: when passed the addresses of two variables, the function should exchange the values of the variables:
swap(&i, &j); /* exchange values of i and j */

Your program will call find_largest function and swap function in selection_sort function.

A vector is an ordered collection of values in mathematics. An array is a very straightforward way to implement a vector on a computer. Two vectors are multiplied on an entry-by-entry basis, e.g. (1, 2, 3) * (4, 5, 6) = (4, 10, 18).

Write a program that include the following functions. The functions should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the functions.

void multi_vec (int *v1, int *v2, int *v3, int n);
int comp_vec(int *v1, int *v2, int n);

The multi_vec function multiplies vectors v1 and v2 and stores the result in v3. n is the length of the vectors.

The comp_vec function compares v1 and v2, return 1 if vectors v1 and v2 are equal (their corresponding components are equal), and 0 otherwise. n is the length of the vectors.

In the main function, ask the user to enter the length of the vectors, declare two arrays with the length, read in the values for two vectors, and call the two functions to compute the multiplication and comparison of them. The main function should display the result.

Enter the length of the vectors: 5

Enter the first vector: 3 4 9 1 4

Enter the second vector: 5 7 2 6 8

Output:

The multiplication of the vectors is: 15 28 18 6 32

The vectors are not the same.

Before you submit:

1. Compile with -Wall. Be sure it compiles on circe with no errors and no warnings.

gcc -Wall selection_sort.c
gcc -Wall vector.c

2. Be sure your Unix source file is read & write protected. Change Unix file permission on Unix:

chmod 600 selection_sort.c
chmod 600 vector.c

3. Test your program with the shell scripts on Unix:

chmod +x try_sort
./try_sort
chmod +x try_vector
./try_vector

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Modify selectionsortc so that it includes the following
Reference No:- TGS01225359

Now Priced at $35 (50% Discount)

Recommended (97%)

Rated (4.9/5)

A

Anonymous user

2/22/2016 7:04:49 AM

For the above programming assignment, i got the best solution via the tutors of this respective website. They provide all the coding part as well as all the outputs all along with respective snapshots. I am obliged with their hard work and will always pursue their assistance whenever required.