Question: Use c code Part I Write a program that asks the user to enter 10 integers and stores them in an array. Write a function
Use c code
Part I
Write a program that asks the user to enter 10 integers and stores them in an array.
Write a function that takes as input an array and its length and prints the content of the array separated
by tabs. Modify your program so it prints the content of the array after initializing it from the user input
(use the function you wrote).
Write a function called largest (outside of the main function) that takes as input an array of int, the length of the array, and an index of the array and returns the largest element of the array between the given index and the end of the array.
Your program should then ask the user for a position and use the function largest to return the largest
element starting at that position.
Compile and test your program.
The following declaration is an example of passing an array and its length as the parameters to a
function:
void sampleFunction(int array[], int size)
Part II
Modify your function, change its name to largestPos and update its code so it returns the position of the
largest element found. Change your program so it prints the largest element in the array starting at the
user given position.
Part III
Make changes such that your sort.c program does the following:
- Ask the user to enter an integer between 2 and 15. This will represent the number of elements
in the array
- Check if the input is between 2 and 15. If not, your program should keep asking the user to enter
an integer between 2 and 15 until a valid input is entered
- Ask the user to enter the specified number of integers
- Read those integers into an array
- Print the array before sorting
- Sort the array in decreasing order using bubble sort (assume that the last index of the array is
LAST):
o Find the largest element of the array (use the function written in part II)
o Swap the largest element with the element at position 0
o Find the largest element between position 1 and LAST
o Swap the largest element with the element at position 1
o Find the largest element between position 2 and LAST
o Swap the largest element with the element at position 2
o Repeat until all elements are sorted
- Print the array after sorting
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
