hal 541
Problem :
Sort an array ascending order using a selection sort.
Dev c++ :
Sort an array ascending order using a selection sort.
Dev c++ :
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int i, j, max, temp;
int data[10];
cout<<"---Selection Sort---"<<endl;
cout<<"Masukkan banyak data=";
cin>>max;
for(i=1;i<=max;i++){
cout<<"Masukkan data ke-"<<i<<" : ";
cin>>data[i];
}
cout<<" Data Awal :";
for(i=1;i<=max;i++){
cout<<data[i]<<" ";
}
for(i=1;i<max;i++){
for(j=i+1;j<=max;j++){
if(data[i]>data[j]){
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
}
}
cout<<"\n Setelah di Urutkan: ";
for(i=1;i<=max;i++){
cout<<data[i]<<" ";
}
return 0;
}
untuk 538 di fafa145.blogspot.co.id
untuk 419 di pengantarprogram.blogspot.co.id
Komentar
Posting Komentar