wap to sort an int of 5 elements in asending & desending both order

/*wap to sort an int of 5 elements in asending & desending order*/

#include<stdio.h>
#include<conio.h>

void main()

{
 int n[5],i=0,j=0,temp=0;
 clrscr();

 printf("Enter any 5 int to sort them in Ascending & Descending order:\n");
 for(i=0;i<5;i++)
 {
  scanf("%d",&n[i]);
 }

 printf("\nDescending:\tAscending:\n\n");

 for(i=0;i<5;i++)
 {
  for(j=i+1;j<5;j++)
  {
   if(n[i]<n[j])
   {
    temp=n[j];
    n[j]=n[i];
    n[i]=temp;
   }
  }
 }

 for(i=0,j=4;i<=4,j>=0;i++,j--)
 {
  printf("%d\t\t%d\n",n[i],n[j]);
 }

 getch();
}

No comments:

Post a Comment