# c program on bubble sort.

__ what is bubble sort:-__

Bubble sort is a simple sorting algorithm in which we sort the element by repeatedly swap the element if they are in wrong order.

**Example:****First Cycle:**

( 6 **1** 3 2 9 ) –> ( **1** **6 3** 2 9 ), Here, in this algorithm we compares the first two elements, and swaps since 6>1.

( 1 **6** **3** 2 9 ) –> ( 1 **3 6** 2 9 ), Swap since 6>3

( 1 3 **6** **2** 9 ) –> ( 1 3 **2 6** 9 ), Swap since 6 > 2

( 1 3 2 **6**** 9 ** ) –> ( 1 3 2 **6** **9** ), Now, since these elements are already in order (9>6), so algorithm does not swap them.

**Second Cycle:**

(**1 3 **2 6 9) –> (**1 3** 2 6 9 )

( 1 **3 2** 6 9 ) –> ( 1 **2** **3** 6 9 ), Swap since 3>2

( 1 3** 2 6** 9) –> ( 1 3 2 6 9),

( 1 3 2 **6** **9** ) –> (1 3 2 **6** **9** )

Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one **whole** pass without **any** swap to know it is sorted.

**Third Cycle:**

( **1 3**** **2 6 9 ) –> ( **1 3** 2 6 9 )

( 1 **3 2** 6 9 ) –> ( 1** 2 3** 6 9)

( 1 2** 3 6 **9 ) –> ( 1 2 **3 6** 9 )

( 1 2 3 **6 9**** **) –> ( 1 2 3 **6 9** )

And finally we find the sorted array

**1 2 3 6 9**

**Code:-**

**Output:-**