BUBBLE SORT
unknown
plain_text
3 years ago
652 B
2
Indexable
Never
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { int array[100], n, i, j, swap; printf("Enter number of elementsn"); scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &array[i]); for (i = 0; i < n - 1; i++) { for (j = 0; j < n - i - 1; j++) { if (array[j] > array[j + 1]) { swap = array[j]; array[j] = array[j + 1]; array[j + 1] = swap; } } } printf("Sorted Array: \n"); for (i = 0; i < n; i++) printf("%dn", array[i]); return 0; }