#include <iostream>
using namespace std; 
class sort 
{
    int a[100],i, j, n, t; 
    public :
    void getdata ();
    void ascending ();
    void descending ();
};
void sort::getdata ()
{
    cout <<"Enter the no. of elements you want to sorting: ";
    cin>>n; 
    cout <<n<<endl; 
    cout <<"Enter the elements :"<<endl; 
    for (i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout <<"Elements are :"<<endl;
    for (i=0;i<n;i++)
    {
        cout <<a[i]<<"\t";
    }
}
void sort ::ascending ()
{
    cout <<"\n Ascending order :"<<endl; 
    for (i=0;i<n;i++)
    {
        for (j=i+1;j<n;j++)
        {
            if (a[i]>a[j])
            {
                t=a[i];
                a[i]=a[j];
                a[j]=t; 
            }
        }
    }
    for (i=0;i<n;i++)
    {
        cout <<a[i]<<"\t";
    }
}
void sort ::descending ()
{
    cout <<"\n Descending order "<<endl; 
    for (i=n-1;i>=0;i--)
    {
        cout <<a[i]<<"\t";
    }
}
int main() {
 sort obj; 
 obj. getdata();
 obj. ascending ();
 obj. descending ();
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: