Source Code Selection Sort

Leave a Comment
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

void sort (int a[],int i)
{
int j;
int temp;
int langkah;
temp=0;
i=0;
langkah=0;
while(i<9)
{
j=i+1;
while (j<9)
{
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
else
{
}
j=j+1;
}
i=i+1;
while (langkah<9)
{
cout<<a[langkah]<<" , ";
langkah = langkah+1;
}
cout<<" "<<endl;
langkah=0;
}
cout<<endl;
cout<<"Hasil pengurutan = ";
i=0;
while(i<9)
{
cout<<a[i]<<" , ";
i=i+1;
}
}
int main()
{
int i=0;
int a[9];
while (i<9)
{
{
cout<<"Masukkan nilai ke- "<<i<<" = ";
// cout <<endl;
cin>>a[i];
i=i+1;
}
}
sort(a,i);
getch();
return 0;
}



0 komentar:

Posting Komentar

Gieovanni Wisnu Pramudya - 2017. Diberdayakan oleh Blogger.

Recent

Comment