Program to sort an array of integers in ascending order using bubble sort.

#include <iostream>
using namespace std;

void bubble(int arr[],int n)
{
  for(int i=0;i<n;++i)
    for(int j=0;j<n-i-1;++j)
   if (arr[j]>arr[j+1])
   {
       int temp=arr[j];
       arr[j]=arr[j+1];
       arr[j+1]=temp;
   }
}

int main()
{
    int input[] = {10, 50, 21, 2, 6, 66, 802, 75, 24, 170};
  int n=sizeof(input)/sizeof(input[0]);
  bubble(input,n);
    cout<<"Sorted Array : \n";
 for(int i=0;i<n;++i)
  cout<<input[i]<<" ";
cout<<"\n/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
    return 0;
}

Output:


Comments

Popular posts from this blog

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN