Write a program to sort the elements of an array in descending order.
# include
# include
void main()
{
int a[20],n,i,j,t;
clrscr();
printf("Enter the number of elements in an array:");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the %d value:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i {
for(j=i;j {
if(a[i] {
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i printf("\n%d",a[i]);
getch();
}
/* Output
Enter the number of elements in an array:3
Enter the 1 value:6
Enter the 2 value:5
Enter the 3 value:8
8
6
5
*/
# include
# include
void main()
{
int a[20],n,i,j,t;
clrscr();
printf("Enter the number of elements in an array:");
scanf("%d",&n);
for(i=0;i
printf("\nEnter the %d value:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i
for(j=i;j
if(a[i] {
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i
getch();
}
/* Output
Enter the number of elements in an array:3
Enter the 1 value:6
Enter the 2 value:5
Enter the 3 value:8
8
6
5
*/