#include <cstdlib>
#include <iostream>
using namespace std;
void baca_data(int A[], int n){
int i;
for(i=0;i<n;i++){
cout<<"Data ke- " <<i+1 <<" : "; cin>>A[i];
}
}
void cetak_data(const int A[],int n){
int i;
for(i=0;i<n;i++)
cout<<A[i] <<" " <<endl;
}
void tukar(int *a,int *b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void buble(int x[], int n){
int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++){
if(x[i] > x[j]) tukar(&x[i],&x[j]);}
}
int main(int argc, char *argv[])
{
int data[10],n;
cout<<"Banyak data : "; cin>>n;
baca_data(data,n);
cout<<endl <<"DATA AWAL " <<endl;
cout<<"***************************************" <<endl;
cetak_data(data,n);
buble(data,n);
cout<<endl <<endl <<"SETELAH DIURUTKAN "<<endl;
cout<<"***************************************" <<endl;
cetak_data(data,n);
cout<<endl<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Kamis, 01 Maret 2012
Shorting
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar