0% found this document useful (0 votes)
30 views2 pages

Practical No 07

The document provides a program that implements the bubble sort algorithm to sort an array of integers. It includes a main function to input the number of elements and the integers themselves, followed by a bubble_sort function that sorts the array in ascending order. An example output is also shown, demonstrating the sorting of a sample input array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Practical No 07

The document provides a program that implements the bubble sort algorithm to sort an array of integers. It includes a main function to input the number of elements and the integers themselves, followed by a bubble_sort function that sorts the array in ascending order. An example output is also shown, demonstrating the sorting of a sample input array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No:07

AIM: WRITE A PROGRAME TO SORT AN ARRAY USING (BUBBLE SORT )


NAME: Shreyash P. Bayskar
Output:
void bubble_sort(long [], long);
int main()
{
long array[100], n, c;
printf("Enter number of elements\n");
scanf("%ld", &n);
printf("Enter %ld integers\n", n);
for (c = 0; c < n; c++)
scanf("%ld", &array[c]);
bubble_sort(array, n);
printf("Sorted list in ascending order:\n");
for (c = 0; c < n; c++)
printf("%ld\n", array[c]);
return 0;
}
void bubble_sort(long list[], long n)
{
long c, d, t;
for (c = 0 ; c < n - 1; c++) {
for (d = 0 ; d < n - c - 1; d++) {
if (list[d] > list[d+1]) {
t = list[d];
list[d] = list[d+1];
list[d+1] = t;
}
}
}
}
Output:
//Enter number of elements
5
Enter 5 integers
25738
Sorted list in ascending order:
2
3
5
7
8 //

You might also like