/* Program to sort
the elements of the array in descending order */
#include<stdio.h>
#include<conio.h>
void
main()
{
int arr[100],temp,n,i,j;
clrscr();
printf("Enter the number of elements in
the array:");
scanf("%d",&n);
printf("\nElements-->");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
/* Sorting of elements */
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]<arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
printf("\n\nElements of array in
descending order are:\n");
for(i=0;i<n;i++)
{
printf("\t%d",arr[i]);
}
getch();
}
OUTPUT
Enter
the number of elements in the array:5
Elements-->23
13
47
61
53
Elements
of array in descending order are:
61
53 47 23
13
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.