Kamis, 26 Juni 2014

Contoh program sorting C++




 Source code
#include <iostream.h>

#include <conio.h>

void main() {

{

int bil[20],a,b,c,i;

cout<<"masukan  jumlah data = ";

cin>>c;

for(i=1;i<=c;i=i+1)

{

cout<<"masukan data ke "<< i<<" = ";

cin>>bil[i];

}

cout<<"Data sebelum di sorting :\n";

for(i=1;i<=c;i=i+1)

cout<<" "<<bil[i];

for(i=1;i<=c;i=i+1)

for(a=i+1;a<=c;a=a+1)

if(bil[i]>bil[a])

{

b=bil[i];

bil[i]=bil[a];

bil[a]=b;

}

cout<<"\n";

cout<<"Data setelah di sorting :\n";

for(i=1;i<=c;i=i+1)

cout<<" "<<bil[i];

}

getch();}

Tidak ada komentar:

Posting Komentar