The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Can you please help? Â I'm a first timer and had other projects but this seems to be difficult
Â
Project 6, Program Design1.This program will be graded based on whether the required functionality wereimplemented correctly instead of whether it produces the correct output, for thefunctionality part (80% of the grade).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 apointer to the array’s largest element.The function should use pointer arithmetic – notsubscripting – to visit array elements. In other words, eliminate the loop index variablesand all use of the [] operator in the function.swap function: when passed the addresses of two variables, the function shouldexchange 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_sortfunction.2.A vector is an ordered collection of values in mathematics. An array is a verystraightforward way to implement a vector on a computer. Two vectors are multipliedon 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 pointerarithmetic (instead of array subscripting). In other words, eliminate the loop indexvariables and all use of the [] operator in the functions.void multi_vec (int *v1, int *v2, int *v3, int n);
/*selection_sort.c, project 6, Program Design*/#include <stdio.h>#define N 10void selection_sort(int a[], int n);int main(void){int i;int a[N];printf("Enter %d numbers to be sorted: ", N);for (i = 0; i < N; i++)scanf("%d", &a[i]);selection_sort(a, N);printf("In sorted order:");for (i = 0; i < N; i++)printf(" %d", a[i]);printf("\n");return 0;}void selection_sort(int a[], int n){int i, largest = 0, temp;if (n == 1)return;for (i = 1; i < n; i++)if (a[i] > a[largest])largest = i;if (largest < n - 1) {temp = a[n-1];a[n-1] = a[largest];a[largest] = temp;}selection_sort(a, n - 1);}
Attachments:
-----------