Q28.Write a code to sort array elements in ascending order using bubble sort

Bubble Sort :- Bubble sort is also known as sinking sort. Bubble sort is a simple sorting algorithm that compares adjacent elements and swaps them if order is wrong.

Ascending Order :- Numbers are said to be in ascending order when they are arranged from smallest to largest number. Such as 2, 3, 5, 9 and 11 are arranged in ascending order.

Arrange Array elements in ascending order using Bubble Sort Algorithm 

START
Step 1: Repeat Step 2 For i = 0 to N
Step 2: Repeat For J = 0 to N – I
Step 3: IF A[J] > A[J+1]
SWAP A[J] and A[J+1]
[END OF INNER LOOP]
[END OF OUTER LOOP
Step 4: EXIT
STOP

Arrange Array elements in ascending order using Bubble Sort Code

Output

Sorted Array: 2 3 5 7 8

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number