write a program that asks the user to enter a series of integers then sorts the
ID: 3641372 • Letter: W
Question
write a program that asks the user to enter a series of integers then sorts the integers by calling the function selection_sort.When given an array with n elements, selection_sort must do the following:1.Search the array to find the largest element then move it to last position array.2.call itself recursively to sort the first n-1 elements of the array.Explanation / Answer
#include #include int * selection_sort(int arr[],int n){ int i, j, temp ; while(n>=1){ for ( j = n - 1 ; j >= 0 ; j-- ) { if ( arr[n] arr[i] ... swap and put at the end { temp = arr[n] ; arr[n] = arr[j] ; arr[j] = temp ; } } n--; arr=selection_sort(arr,n); // recursive call to the selection_sort } } void main( ) { int i,n; printf(" Enter the value of n "); scanf("%d",&n); int *arr = (int*)malloc(n*sizeof(int)) ; int *res_arr = (int*)malloc(n*sizeof(int)) ; for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.