diff --git a/BubbleSort.c b/BubbleSort.c new file mode 100644 index 0000000..e35ac00 --- /dev/null +++ b/BubbleSort.c @@ -0,0 +1,38 @@ +// WAP to sort an array using bubble sort. + +void main() { + int array[10], n, c, d, swap; + + // To set range of array: + printf("\n Enter the range of array: \n"); + scanf("%d", &n); + + // To get values of array: + printf("\n Enter the elements of the array: \n"); + for (c=0 ; c<=n; c++) { + scanf("%d \n", &array[c]); + } + + // To print the elements of the insorted array: + printf("\n The elements of the unsorted array are: \n"); + for (c=0 ; c<=n; c++) { + printf("%d \n", array[c]); + } + + // Bubble Ssort algorithm: + for (c=0 ; c<=n-1; c++) { + for (d=0; d array[d+1]) { + swap = array[d+1]; + array[d] = array[d+1]; + array[d+1] = swap; + } + } + } + + // To print the elements of the sorted array: + printf("\n The elements of the sorted array are: \n"); + for (c=0 ; c<=n; c++) { + printf("\n %d \n", array[c]); + } +} \ No newline at end of file diff --git a/BubbleSort.exe b/BubbleSort.exe new file mode 100644 index 0000000..5f67e63 Binary files /dev/null and b/BubbleSort.exe differ diff --git a/Order Of Programs.md b/Order Of Programs.md index 11df9d5..3f51755 100644 --- a/Order Of Programs.md +++ b/Order Of Programs.md @@ -25,4 +25,5 @@ |23 | MultiplicationTable.c | MultiplicationTable.exe | WAP to print the multiplication table for a given number | |24 | Divisible.c | Divisible.exe | WAP to find an addition of numbers which are >30, <100 & divisible by 7 | |25 | Array.c | Array.exe | WAP to print out an array of dynamic values | -|26 | ArrayReverse.c | ArrayReverse.exe | WAP to print out an array of dynamic values in reverse order | \ No newline at end of file +|26 | ArrayReverse.c | ArrayReverse.exe | WAP to print out an array of dynamic values in reverse order | +|27 | BubbleSort.c | BubbleSort.exe | WAP to sort an array using bubble sort | \ No newline at end of file