Tuesday, April 7, 2015

45. Write a program to sort an array of "n" elements in descending order.


#include <stdio.h>
#include <conio.h>
void main()
{
int num[100],i,j,n,temp;
clrscr();
printf("\n How many data:- ");
scanf("%d",&n);
printf("\n Input %d data's:- ",n);
for(i=0;i<n;i++)
{
printf("\n num[%d]:-",i);
scanf("%D",&num[i]);
}
for(i=0;i<n;i++)
{
  for(j=i+1;j<n;j++)
     {
      temp=num[i];
      num[i]=num[j];
      num[j]=temp;
     }
  }
}
printf("\n The data in descending orders are: \n");
for(i=0;i<n;i++)
{
printf("%5d",num[i]);
}
getch();
}

No comments:

Post a Comment