Question: Write a C program main program that: 1. Use a #define constant to define the size of your array. 2. Prompts the user to enter

Write a C program
main
program that:
1.
Use a #define constant to define the size of
your array.
2.
Prompts the user to enter 5 integer values.
3.
Reads the 5 integer values and stores them in an array.
4.
Prints out the 5 values in their original order.
5.
Calls a
Bubble
Sort
function that you write and passes to it your array of data and the size
of
the array.
Your Bubble
Sort function sorts the numbers from lowest to largest and
returns the sorted array.
6.
Prints out the 5 values in order of lowest to largest.
Write a BubbleSort
()
function
that:
1.
R
eceives
an array of integers and the size of the array.
2.
Sorts the array using
the bubble sort method.
a.
Bubble sort uses 2 for loops
:
i.
The inner loop compares adjacent values and swaps them if the second
value is smaller than the first value. One pass through the a
rray will
move the largest value to the end of the array. It also sets a flag when a
swap occurs.
ii.
The outer loop keeps executing the inner loop until the flag indicates that
no swaps occurred.
1.
Although there are ways that the bubble function can be
optimi
zed, you do not need to do the optimizations.
b.
Here is a
link with information on the bubble sorting in C.
i.
http://www.c4learn.com/c
-
programs/program
-
bubble
-
sort
-
elemets
-
in
-
c
-
all.html
3.
Do
es
not use any of the C minimum
,
maximum
, or sort
functions in your function.
Use
the comparison operators to do your comparisons for the sorting.
Example output would be:
Enter
5
integer
values
:
4
23 41 8 15
Initial array
: 4
23
41
8
15
Sorted array:
4 8 15 23 41
Write a main program that: 1. Use a define constant to define the size of your amay. 2. Prompts the user to enter 5 integer values. 3. Reads the 5 integer values and stores them in an array. 4. Prints out the 5 values in their original order. 5. Calls a BubbleSort function at you write and passes to it your array of data and the size of the array. Your BubbleSort ction sorts the numbers from lowest to largest and returns the sorted array. 6. Prints out the 5 es in order of lowest to largest. Write a BubbleSort0 function that: 1. Receives an array of integers and the size of the amay. 2. Sorts the arrayusing the bubble sort method. a. Bubble sort uses 2 for loops: i. The inner loop compares adjacent values and swaps them if the second value is smaller than the first value. One pass through the array will move the largest value to the end of the amay. lt also sets a flag when a ii. The outer loop keeps executing the inner loop until the flag indicates that Swap occurs no swaps occurred. l. Although there are ways that the bubble function can be optimized, you do not need to do the optimizations. b. Here is a link with information on the bubble sorting in C i. http://www.c4leam.com/c-programs bubble-so all.html 3. Does not use any of the C minimuluILL. ILaximum, or sort functions in your function. Use the comparison operators to do your comparisons for the sorting. Example output would be: Enter 5 integer values 4 23 41 8 15 Initial array: 4 23 11 8 15 Sorted array: 1 8 15 23 Al Note: Pages 401 and 402 in our book provide informalion on passing arrays (o junclions and using the array in the function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
