#pragma argsused
#include<iostream.h>
#include<conio.h>
int main()
{
int nilai[20];
int i,x,j,k,temp;
cout<<"Mengurutkan Data Nilai"<<endl;
cout<<"======================"<<endl;
cout<<endl;
cout<<"Masukkan Banyak Input = ";cin>>x;
cout<<"------------------------"<<endl;
for(i=1;i<=x;i++)
{
cout<<"Nilai Ke-"<<i<<" : "; cin>>nilai[i];
}
cout<<endl;
cout<<"----------------------------"<<endl;
cout<<"Input sebelum diurutkan : "<<endl;
for(i=1;i<=x;i++)
{
cout<<nilai[i]<<" ";
}
cout<<endl;
cout<<endl;
for(j=1;j<=x;j++)
{
for(k=j+1;k<=x;k++)
{
if(nilai[j]>nilai[k])
{
temp=nilai[j];
nilai[j]=nilai[k];
nilai[k]=temp;
}
}
}
cout<<"Input setelah diurutkan : "<<endl;
for(i=1;i<=x;i++)
{
cout<<nilai[i]<<" ";
}
getch();
}
0 comments:
Post a Comment