# Sort an Array in Ascending or Descending order using Function Pointers

## Code:

#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int num[10],i,j,temp;
cout<<“Enter Any Numbers:\n”;
for(i=1;i<=10;i++)
{
cin>>num[i];
}
cout<<“Inpute Array is: “;
for(i=1;i<=10;i++)
{
cout<<num[i]<<” “;
}

for(i=1;i<=10;i++)
{
for(j=1;j<=10-i;j++)
{
if(num[j]>num[j+1])
{
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
cout<<“\n\nArray in Ascending Order: “;
for(j=1;j<=10;j++)
{
cout<<num[j]<<” “;
}
cout<<“\n\nArray in Descending Order: “;
for(j=10;j>=1;j–)
{
cout<<num[j]<<” “;
}
_getch();
}

```#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
int num[10],i,j,temp;
cout<<"Enter Any Numbers:\n";
for(i=1;i<=10;i++)
{
cin>>num[i];
}
cout<<"Inpute Array is: ";
for(i=1;i<=10;i++)
{
cout<<num[i]<<" ";
}

for(i=1;i<=10;i++)
{
for(j=1;j<=10-i;j++)
{
if(num[j]>num[j+1])
{
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
cout<<"\n\nArray in Ascending Order: ";
for(j=1;j<=10;j++)
{
cout<<num[j]<<" ";
}
cout<<"\n\nArray in Descending Order: ";
for(j=10;j>=1;j--)
{
cout<<num[j]<<" ";
}
_getch();
}
```

## Output:

### 2 thoughts on “Write a program to input elements in an array and sort array using pointers array in ascending or descending order using function pointers.”

1. Tom Michalowsky