- #include <iostream>
- #include <conio.h>
- using namespace std;
- int main() {
- int data[100];
- int i, j, k, tmp;
- cout<<"PROGRAM PENGURUTAN DENGAN BUBBLE SORT\n"<<endl;
- cout<<"Masukkan jumlah bilangan: ";
- cin>>k;
- for(i=0; i<k; i++)
- {
- cout<<"Masukkan angka ke "<<(i+1)<<": ";
- cin>>data[i];
- }
- cout<<"\nAngka sebelum diurutkan: "<<endl;
- for(i=0; i<k; i++)
- {
- cout<<data[i]<<" ";
- }
- cout<<endl;
- for(i=0; i<k; i++)
- {
- for(j=i+1; j<k; j++)
- {
- if(data[i]>data[j])
- {
- tmp=data[i];
- data[i]=data[j];
- data[j]=tmp;
- }
- }
- }
- cout<<"\nAngka setelah diurutkan: "<<endl;
- for(i=0; i<k; i++)
- {
- cout<<data[i]<<" ";
- }
- cout<<endl;
- }
[text] ew
Viewer
Editor
You can edit this paste and save as new:
File Description
- ew
- Paste Code
- 26 Jan-2022
- 877 Bytes
You can Share it: