Bubble Sort 🫧🫧

               // Bubble Sort 





#include <stdio.h>

int main() 

{

int array[50], n. i, j, swap;

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


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


for (i=0; i < n; i++) 

scanf("%d", &array[i]);

for (i=0; i< (n - 1); i++) 

{

for (1 = 0: jn1-1; j++) 

{

if (array[j]> array[j+1]) /* For decreasing order use < */

swap = array[j];

array[j] = array(j + 1]; 

array[j+1]= swap;

}

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

for (i=0; i < n; i++)

printf("%d\n", array[i]);

return 0;

}

Output:

Enter number of elements 5 Enter 5 integers

20

90

0

 -23 

78 

Sorted list in ascending order:

-23 

0

20

78

90 





Comments

Popular posts from this blog

Basic Computer 🖥️💻 Organisation

Introduction of computer 🖥️🖥️🖱️