Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int main()
- {
- int data[100];
- int i, n, temp;
- cout<<"BATAS : ";
- cin>>n;
- cout << endl;
- for(i = 0; i < n; i++)
- {
- cout<<"Nilai ke-"<<i+1<<" : ";
- cin>>data[i];
- }
- for(int i = n/2; i > 0; i=i/2)
- {
- for(int j = i; j < n; j++)
- {
- for (int y = j-i; y >= 0; y = y-1)
- {
- if(data[y+i] < data[y])
- {
- temp=data[y+i];
- data[y+i]=data[y];
- data[y]=temp;
- }
- }
- }
- }
- cout<<"\nSETELAH DIURUTKAN :\n";
- for(i = 0; i < n; i++)
- {
- cout<<data[i]<<" ";
- }
- cout << endl;
- }
Add Comment
Please, Sign In to add comment