Buble Short 2
Buble Short 2
Contoh Program Buble Short
dengan dua inputan
Aplikasi menggunakan borlan C++
Jika belum punya borlan C++ bisa download di menu Aplikasi
#include <iostream.h>
#include <conio.h>
void main()
{
int nim[20], nilai[20];
int temp,jml;
cout<<"masukan jumlah angka: "; cin>>jml;
for ( int a = 1; a<=jml; a++)
{
cout<<"masukan nim ke-"<<a<<" : ";
cin>>nim[a];
cout<<"masukan nilai ke-"<<a<<" : ";
cin>>nilai[a];
}
clrscr();
cout<<"================================================"<<endl;
cout<<"Pengaturan dengan Duble sort"<<endl;
cout<<"================================================"<<endl;
cout<<"Data Sebelum shoting"<<endl;
for (int a=1; a<=jml;a++)
{
cout<<a<<".";
cout<<" "<<nim[a];
cout<<" "<<nilai[a]<<endl;
}
cout<<endl;
//double
for (int a =1; a <=jml; a++)
{
for(int j = 1; j<=jml-1; j++)
{
if (nilai[j]>= nilai[j+1])
{
temp = nilai [j];
nilai [j] = nilai [j+1];
nilai [j+1] = temp ;
temp = nim [j];
nim [j] = nim [j+1];
nim [j+1] = temp ;
}
}
}
cout << "data setelah shorting: "<<endl;
for (int i=1; i<= jml; i++)
{
cout<<i<<".";
cout<<" "<<nim[i];
cout<<" "<<nilai[i]<<endl;
}
getch();
}
#include <conio.h>
void main()
{
int nim[20], nilai[20];
int temp,jml;
cout<<"masukan jumlah angka: "; cin>>jml;
for ( int a = 1; a<=jml; a++)
{
cout<<"masukan nim ke-"<<a<<" : ";
cin>>nim[a];
cout<<"masukan nilai ke-"<<a<<" : ";
cin>>nilai[a];
}
clrscr();
cout<<"================================================"<<endl;
cout<<"Pengaturan dengan Duble sort"<<endl;
cout<<"================================================"<<endl;
cout<<"Data Sebelum shoting"<<endl;
for (int a=1; a<=jml;a++)
{
cout<<a<<".";
cout<<" "<<nim[a];
cout<<" "<<nilai[a]<<endl;
}
cout<<endl;
//double
for (int a =1; a <=jml; a++)
{
for(int j = 1; j<=jml-1; j++)
{
if (nilai[j]>= nilai[j+1])
{
temp = nilai [j];
nilai [j] = nilai [j+1];
nilai [j+1] = temp ;
temp = nim [j];
nim [j] = nim [j+1];
nim [j+1] = temp ;
}
}
}
cout << "data setelah shorting: "<<endl;
for (int i=1; i<= jml; i++)
{
cout<<i<<".";
cout<<" "<<nim[i];
cout<<" "<<nilai[i]<<endl;
}
getch();
}
No comments :
Post a Comment