Reference no: EM132194770
Question :
Write a C program called sort.c that first prompts the user for a positive number n representing the number of numbers to be sorted.
Next, it prompts the user to enter the numbers in an arbitrary order and store them in an array of size n (numbers[n]).
The program then takes the following approach to sort the numbers in the array:
it stores the value of n in a temporary variable temp,
it searches for the largest number in the array, starting with position 0 and ending with position temp-1.
To find largest element in the array write a function
int getMax (int numbers[], int n);
(or)
try using int getMax (*list, int n);//this involves the concept of pointers.
This function determines the largest value in an array and returns its location in the array. The parameter n indicates the number of values in the array.
The parameter list is the array of integers.
it then switches the field that stores the largest value with the field indexed by temp-1, this is done by employing a function
void switchValue ( int *a, int *b )
the program decrements temp by 1 (temp--),
the program repeats steps {b-d} until temp is decremented to 1 in step d.
Output: Print the sorted array (ascending order)