From 5ebc9bfa3f3da978766f96fc73f95d08eff95755 Mon Sep 17 00:00:00 2001 From: Akanksha Gupta <114081059+Akanksha038@users.noreply.github.com> Date: Mon, 17 Oct 2022 23:02:07 +0530 Subject: [PATCH] Added Bubble Sort program in C --- C/bubble Sort.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 C/bubble Sort.c diff --git a/C/bubble Sort.c b/C/bubble Sort.c new file mode 100644 index 0000000..90e794d --- /dev/null +++ b/C/bubble Sort.c @@ -0,0 +1,34 @@ +#include + +int main() +{ + int array[100], n, c, d, swap; + + printf("Enter number of elements\n"); + scanf("%d", &n); + + printf("Enter %d integers\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + for (c = 0 ; c < n - 1; c++) + { + for (d = 0 ; d < n - c - 1; d++) + { + if (array[d] > array[d+1]) + { + swap = array[d]; + array[d] = array[d+1]; + array[d+1] = swap; + } + } + } + + printf("Sorted list in ascending order:\n"); + + for (c = 0; c < n; c++) + printf("%d\n", array[c]); + + return 0; +} \ No newline at end of file