From 0f70e6e094cb52293272d5fa3c680ab72d85013a Mon Sep 17 00:00:00 2001 From: Dikshant Gautam Date: Sun, 10 Oct 2021 18:24:44 +0530 Subject: [PATCH] Create bubblesortinc.c --- bubblesortinc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 bubblesortinc.c diff --git a/bubblesortinc.c b/bubblesortinc.c new file mode 100644 index 0000000..9029d9e --- /dev/null +++ b/bubblesortinc.c @@ -0,0 +1,36 @@ +#include + void print(int a[], int n) //function to print array elements + { + int i; + for(i = 0; i < n; i++) + { + printf("%d ",a[i]); + } + } + void bubble(int a[], int n) // function to implement bubble sort + { + int i, j, temp; + for(i = 0; i < n; i++) + { + for(j = i+1; j < n; j++) + { + if(a[j] < a[i]) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + } +void main () +{ + int i, j,temp; + int a[5] = { 10, 35, 32, 13, 26}; + int n = sizeof(a)/sizeof(a[0]); + printf("Before sorting array elements are - \n"); + print(a, n); + bubble(a, n); + printf("\nAfter sorting array elements are - \n"); + print(a, n); +}