User Tools

Site Tools


c_-_c_sorts:bubble_sort

C - C++ Sorts - Bubble Sort

#include <iostream>  
using namespace std; 
 
int main() 
{ 
  int a[5],i,j,t;
 
  cout<<"\nEnter five elemnts:";
 
  for(i=0;i<5;i++)
    cin>>a[i];
 
  for(i=0;i<5;i++)
    for(j=i+1;j<5;j++)
      if(a[i]>a[j])
      {
        t=a[i];
        a[i]=a[j];
        a[j]=t;
      }
 
  cout<<"\n Ascending order\n";
 
  for(i=0;i<5;i++)
    cout<<a[i]<<"\n";
 
  cout<<"\n Descending order\n";
 
  for(i=4;i>=0;i--)
    cout<<a[i]<<"\n";
 
  return 0;
}
c_-_c_sorts/bubble_sort.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki