Plzzz solve it Write a program that calls the functions int

Plzzz solve it
Write a program that calls the functions int input(float []), void Bubble(int, int []), and void print(int, float []) to sort the elements of an array ascendingly using the bubble sort algorithm. Sample input/output: Enter how many elements in the array: 10 Enter 10 values: 3 7 4 9 7 11 15 10 7 8 The array before sorting: 3 7 4 9 7 11 15 10 7 8 The array after sorting: 3 4 7 7 7 8 9 10 11 15

Solution

#include <stdio.h>

void bubble_sort(int [], int);

int main()
{
int array[100], n, c, d, swap;

printf(\"Enter number of elements\ \");
scanf(\"%d\", &n);

printf(\"Enter %d integers\ \", n);

for (c = 0; c < n; c++)
scanf(\"%d\", &array[c]);

bubble_sort(array, n);

printf(\"Sorted list in ascending order:\ \");

for ( c = 0 ; c < n ; c++ )
printf(\"%d\ \", array[c]);

return 0;
}

void bubble_sort(int list[], int n)
{
int c, d, t;

for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (list[d] > list[d+1])
{
/* Swapping */

t = list[d];
list[d] = list[d+1];
list[d+1] = t;
}
}
}
}

Plzzz solve it Write a program that calls the functions int input(float []), void Bubble(int, int []), and void print(int, float []) to sort the elements of an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site