#include<iostream>
using namespace std;
int main()
{
int n,i,j,k,temp;
cout<<"Enter your total number here";
cin>>n;
int a[n];
cout<<endl<<"enter element for first array"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cin>>a[j];
cout<<endl;
}
cout<<"before Exchange"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cout<<a[j];
cout<<endl;
}
for(j=0;j<n;j++)
{
for(i=j;i<n;i++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
cout<<"after ascending sorting"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cout<<a[j];
cout<<endl;
}
cout<<"after descending sorting"<<endl;
for(j=n-1;j>=0;j--)
{
cout<<"Enter element at position " <<n-j<<" :";
cout<<a[j];
cout<<endl;
}
return 0;
}
using namespace std;
int main()
{
int n,i,j,k,temp;
cout<<"Enter your total number here";
cin>>n;
int a[n];
cout<<endl<<"enter element for first array"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cin>>a[j];
cout<<endl;
}
cout<<"before Exchange"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cout<<a[j];
cout<<endl;
}
for(j=0;j<n;j++)
{
for(i=j;i<n;i++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
cout<<"after ascending sorting"<<endl;
for(j=0;j<n;j++)
{
cout<<"Enter element at position " <<j+1<<" :";
cout<<a[j];
cout<<endl;
}
cout<<"after descending sorting"<<endl;
for(j=n-1;j>=0;j--)
{
cout<<"Enter element at position " <<n-j<<" :";
cout<<a[j];
cout<<endl;
}
return 0;
}
No comments:
Post a Comment