You are on page 1of 1

1: /* C++ Program - Bubble Sort */

2: #include<iostream>
3: #include<conio.h>
4: using namespace std;
5: int main()
6: {
7:
8: int n, i, arr[50], j, temp;
9: cout<<"Enter total number of elements :";
10: cin>>n;
11: cout<<"Enter "<<n<<" numbers :";
12: for(i=0; i<n; i++)
13: {
14: cin>>arr[i];
15: }
16: cout<<"Sorting array using bubble sort technique...\n";
17: for(i=0; i<(n-1); i++)
18: {
19: for(j=0; j<(n-i-1); j++)
20: {
21: if(arr[j]>arr[j+1])
22: {
23: temp=arr[j];
24: arr[j]=arr[j+1];
25: arr[j+1]=temp;
26: }
27: }
28: }
29: cout<<"Elements sorted successfully..!!\n";
30: cout<<"Sorted list in ascending order :\n";
31: for(i=0; i<n; i++)
32: {
33: cout<<arr[i]<<" ";
34: }
35: getch();
36: return 0;
37: }
38:

You might also like