0% found this document useful (0 votes)
22 views

Bubble

This document provides code to perform bubble sort on an array of integers. The code first prompts the user to enter the size of the array and its elements. It then performs two nested for loops to compare adjacent elements, swapping any that are out of order. After sorting, the code prints out the sorted array.

Uploaded by

Swapnil Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Bubble

This document provides code to perform bubble sort on an array of integers. The code first prompts the user to enter the size of the array and its elements. It then performs two nested for loops to compare adjacent elements, swapping any that are out of order. After sorting, the code prints out the sorted array.

Uploaded by

Swapnil Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Q 9. WAP to perform sorting using bubble sort .

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,t,a[30],n;
cout<<"Enter limit ";
cin>>n;
cout<<"Enter elements to be sorted \n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j+1];
a[j+1]=a[j];
a[j]=t;
}
}
}
cout<<"After sorting \n";
for(i=0;i<n;i++)
{
cout<<a[i];
cout<<endl;
}
getch();
}

You might also like