[text] ew

Viewer

  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int data[100];
  7.     int i, j, k, tmp;
  8.  
  9.     cout<<"PROGRAM PENGURUTAN DENGAN BUBBLE SORT\n"<<endl;
  10.     cout<<"Masukkan jumlah bilangan: ";
  11.     cin>>k;
  12.  
  13.     for(i=0; i<k; i++)
  14.     {
  15.         cout<<"Masukkan angka ke "<<(i+1)<<": ";
  16.         cin>>data[i];
  17.     }
  18.  
  19.     cout<<"\nAngka sebelum diurutkan: "<<endl;
  20.  
  21.     for(i=0; i<k; i++)
  22.     {
  23.         cout<<data[i]<<" ";
  24.     }
  25.  
  26.     cout<<endl;
  27.  
  28.     for(i=0; i<k; i++)
  29.     {
  30.         for(j=i+1; j<k; j++)
  31.         {
  32.             if(data[i]>data[j])
  33.             {
  34.                 tmp=data[i];
  35.                 data[i]=data[j];
  36.                 data[j]=tmp;
  37.             }
  38.         }
  39.     }
  40.  
  41.     cout<<"\nAngka setelah diurutkan: "<<endl;
  42.  
  43.     for(i=0; i<k; i++)
  44.     {
  45.         cout<<data[i]<<" ";
  46.     }
  47.  
  48.     cout<<endl;
  49. }

Editor

You can edit this paste and save as new:


File Description
  • ew
  • Paste Code
  • 26 Jan-2022
  • 877 Bytes
You can Share it: