Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void doubleArray (int array[],int s) { for (int i = 0; i < s; i++) array[i] = ar

ID: 3815268 • Letter: V

Question

void doubleArray (int array[],int s)
{
for(int i = 0; i < s; i++)
array[i] = array[i]*2 ;
}

void selectionSort (int array[], int s)
{
int largestIndex ; // index of largest number
int temp; //temporary holds largest number   

for(int last = s - 1 ; last >= 1 ; last --)
{
largestIndex = 0 ;
for(int i = 0; i <= last; i++)
{
if(array[i] > array[largestIndex])
largestIndex = i ;
}
temp = array[largestIndex ];
array[largestIndex] = array[last];
array[last] = temp;
}
}

Enter your choice: 5 1: fill the array 2: print the array 3: calculate the average 4: show the highest number 5: double each number 6: selection sort in descending order 7: sequential search 8: show bar graph 9: quit Enter your choice: 2 The numbers in the array are 20 1632 80 10

Explanation / Answer

HI, Please find my working selection Sort in decreasing order:

void selectionSort(int arr[], int n)
{
int i, j, max_idx;

// One by one move boundary of unsorted subarray
for (i = 0; i < n-1; i++)
{
// Find the maximum element in unsorted array
max_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] > arr[max_idx])
max_idx = j;

// Swap the found maximum element with the first element
int temp = arr[max_idx];
arr[max_idx] = arr[i];
arr[i] = temp
}
}

THis is correct:

void doubleArray (int array[],int s)
{
for(int i = 0; i < s; i++)
array[i] = array[i]*2 ;
}

Please let me know if still you are facing problem