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

The main function should first prompt the user for the elements of an array with

ID: 645502 • Letter: T

Question

The main function should first prompt the user for the elements of an array with N integers and then read in those values The main function should then call the function max_min. The function max_min should compute the maximum and minimum values in the array (using pointers) and pass those values back to main() using pointer parameters. Finally, in main() print out the maximum and minimum values of the array.

#include <stdio.h>

#define N 10

void max_min (int a[], int n, int *max, int *min)

{

int i;

Explanation / Answer

/* This program should display the
* maximum and minimum values
*of an array, as well as display the
*array, sorted in ascending
* order.
*/
#include

/* Function Prototypes */

int find_max(int[], int);
int find_min(int[], int);
int get_min_range(double list[], int first, int last);
int sel_sort(double list[], int n);

int main(void)
{
int nums[] = {5, 3, 0, 9, 8, 1, 7, 4, 10, 2};

printf("nnThe maximum value is %d. n", find_max(nums, 10));
printf("nThe minimum value is %d. n", find_min(nums, 10));

/* The problem may be here
* or in the sel_sort function,
* as far as I can figure.
*/
printf("nThe ascending order of the array is %d n", (nums, 10));
return(0);

}

/* Function that finds largest number */

int find_max(int last[], int num_ele)
{
int i, max = last[0];
for(i = 1; i < num_ele; ++i)

if(max < last[i]) max = last[i];
return(max);
}

/* Function that finds smallest number */

int find_min(int first[], int num_ele)
{
int i, min = first[0];
for(i = 1; i > num_ele; ++i)

if(min > first[i]) min = first[i];
return(min);
}

/* Function that establishes minimum range */

int get_min_range( double list[], int first, int last)
{
int i, small_sub;
small_sub = first;

for(i = first + 1; i <= last; ++i)
small_sub = i;

return(small_sub);
}

/* Function that performs the selection sort */

int sel_sort(double list[], int n)
{
int ele_one, /* First element in unsorted array */
temp, /*Temporary storage for address swapping*/
min_index; /* Subscript of next smaller element */

for(ele_one = 0; ele_one < n-1; ++ele_one)
{
min_index = get_min_range(list, ele_one, n-1);

return(0);
}

/* Exchange elements */

if(ele_one != min_index)
{
temp = list[min_index];
list[min_index] = list[ele_one];
list[ele_one] = temp;
}

return(ele_one);
}