#include<iostream
>
#include<conio.h
>
using namespace std;
int main()
{
int i,j,n,temp;
cout<<"Enter size of array : ";
cin>>n;
int *arr=new int[n];
cout<<"Enter elements of array\n";
for(i=0;i<n
;i++)
{
cin>>arr[i];
}
cout<<"Elements of array\n";
for(i=0;i<n
;i++)
{
cout<<arr[i]<<"\t";
}
cout<<"\nSorted elements of array\n";
for(i=0;i<n
;i++)
{
for(j=0;j<n-i-1
;j++)
{
if(arr[j]<arr[j+1]
)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(i=0;i<n
;i++)
{
cout<<arr[i]
<<"\t";
}
getch();
return 0;
}
No comments:
Post a Comment