Menampilkan Bubble Abjad

Posted by Budi Arieyanto | Posted in | Posted on 02.41

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>

void main()
{
 char bil[8]={ 'a', 'c', 'b', 'e', 'd', 'f', 'g', 'x'};
 int temp;
 cout<<"data sebelum diurutkan; \n";
 for (int ctr=0; ctr<8;ctr++)
  {
      cout<<setw(3)<<bil[ctr];
  }
 cout<<"\n\n";
 for (int i=0; i<7; i++)
  for (char j=0; j<7; j++)
   if(bil[j]>bil[j+1])
    {
     temp=bil[j];
     bil[j]=bil[j+1];
     bil[j+1]=temp;
    }
   cout<<"Data setelah diurutkan : \n";
   for(int k=0; k<8; k++)
    cout<<setw(3)<<bil[k];
   cout<<endl;
  getch();
}

Comments (0)

Posting Komentar