Bubble sort in Single dimensional array

Bubble sort method is one of the must know the sorting algorithm for each and every computer science student.

In this sorting program, we are sorting an integer array of size 10 using bubble sort method.  This method is sorting this array into ascending order.

Bubble sorting on a single dimensional array using functions.

/* Bubble sort program using function and array
#include “io.cpp”
using namespace std;

void output(int a[],int n){
for(int i=0;i<n;i++)

void input(int x[],int n){
for(int i=0;i<n;i++)
cout<<“Enter x[“<<i+1<<“] number : “;

void bubble(int a[],int n){
int i,j,temp;
for(i=0;i<n-1;i++) // steps
temp = a[j];
a[j]= a[j+1];

int main(){
int a[10];
//input phase
//processing phase
// output phase
cout<<“n Sorted array :”;
return 0;

Other useful sorting algorithm are

Selection sort method program using single dimensional array

Insertion sort method program using single dimensional array

Print Friendly, PDF & Email

Related Posts

If you like CBSEToaday and would like to contribute, you can also write an article using submit article or mail your article to contribute@cbsetoday.com See your article appearing on the cbsetoday.com main page and help other students/teachers.