Guest User

Untitled

a guest
Sep 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int data[100];
  9. int i, n, temp;
  10.  
  11. cout<<"BATAS : ";
  12. cin>>n;
  13. cout << endl;
  14. for(i = 0; i < n; i++)
  15. {
  16. cout<<"Nilai ke-"<<i+1<<" : ";
  17. cin>>data[i];
  18. }
  19.  
  20. for(int i = n/2; i > 0; i=i/2)
  21. {
  22. for(int j = i; j < n; j++)
  23. {
  24. for (int y = j-i; y >= 0; y = y-1)
  25. {
  26. if(data[y+i] < data[y])
  27. {
  28. temp=data[y+i];
  29. data[y+i]=data[y];
  30. data[y]=temp;
  31. }
  32. }
  33. }
  34. }
  35.  
  36. cout<<"\nSETELAH DIURUTKAN :\n";
  37. for(i = 0; i < n; i++)
  38. {
  39. cout<<data[i]<<" ";
  40. }
  41. cout << endl;
  42. }
Add Comment
Please, Sign In to add comment