One Piece Going Merry BERKAD11..: SORTING ARRAY TURBO C++

Laman

Sponsor

Tuesday, 30 July 2013

SORTING ARRAY TURBO C++

NIH CONTOH SEDERHANA SORTING ARRAY.....

"Buat yang lagi bingung2 saya share dah hehehe
Silahkan... kalo ada yang maw menambahkan boleh share kok
terima kasih ^_^




#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],i,n,j,temp;
clrscr();
cout<<"Enter the value of n:";
cin>>n;
cout<<"\nEnter the values:\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"Sorted array:\n";
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
getch();
}

No comments:

Post a Comment

Followers

Translate