Bubble Sort

#include <conio.h>
#include <stdio.h>
int main ()
{
int array[5];
cout<<" Masukan angka acak 5 kali :"<<endl;
for (int i=0; i<5; i++)
           {
cin>>array[i];
           }
cout<<endl;
cout<<" Angka yang diinputkan adalah :"<<endl;
for (int j=0; j<5; j++)
           {
cout<<"\tIndexke :"<<j<< "Yaitu :"<<array[j]<<endl;
           }
cout<<endl;
int temp;
for (int i2=0; i2<=4; i2++)
           {
for (int j=0; j<4; j++)
           {
if (array[j]>array[j+1])
           {
temp=array[j];
array[j]=array [j+1];
array[j+1]=temp;
}
}
}
cout<<"hasil sorted array adalah : "<<endl;
for (int i3=0; i3<5; i3++)
{
cout<<"\t\t\tIndexke "<<i3<< " Angkanya adalah :"<<array[i3]<<endl;
}
getch();
}

lau ketik run


Selamat Mencoba

Komentar

Postingan Populer