Hi,
This code accepts 5 integers, copies it to another array(because in the question, it is not mentioned to change the order of the array elements).later it sorts the temp array in ascending order & displays both in ascending and descending order.
#include <stdio.h>
void main()
{
int arr[5],temp[5],i,min,j=0,index;
printf("Enter 5 intergers\n");
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
temp[i]=arr[i];
}
while(j<5)
{
min=temp[j];
for(i=j+1;i<5;i++)
{
if(temp[i]<min)
{
min=temp[i];
index=i;
}
}
if(temp[j] != min)
{
temp[j]=temp[j]+temp[index];
temp[index]=temp[j]-temp[index];
temp[j]=temp[j]-temp[index];
}
j++;
}
printf("Ascending order\n");
for(i=0;i<5;i++)
printf("%d\t",temp[i]);
printf("\n");
printf("Descending order\n");
for(i=4;i>=0;i--)
printf("%d\t",temp[i]);
}