Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
#include stdio.h int main() { int data[100],i,n,step,temp; printf("Enter the number of elements to be sorted: "); scanf("%d",&n); for(i=0;i data[i+1]) /* To sort in descending order, change > to < in this line. */ { temp=data[i]; data[i]=data[i+1]; data[i+1]=temp; } } printf("In ascending order: "); for(i=0;i
Enter the number of elements to be sorted: 6 1. Enter element: 12 2. Enter element: 3 3. Enter element: 0 4. Enter element: -3 5. Enter element: 1 6. Enter element: -9 In ascending order: -9 -3 0 1 3 13