sort the array in descending order by R4R Team

Array:
Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

Example-
Array is {3,2,4,1,5}
Sorted Array is {5,4,3,2,1}

program-

#include < stdio.h>
int main()
{
int a[100],i,j,t,n;
printf("Number of elements in array ?\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
//Input in array
for(i=0;i< n;i++){
scanf("%d",&a[i]);
}
//Sort the Array
for(i=0;i< n;i++)
{
for(j=i;j< n;j++)
{
if(a[j]>a[i])
{
t=a[j];
a[j]=a[i];
a[i]=t;
}
}
}
//Traverse
printf("Array is\n");
for(i=0;i< n;i++)
printf("%d,",a[i]);
}


output-

Number of elements in array ?
6
Enter 6 number in array
6 3 48 1 23 2
Array is
48,23,6,3,2,1,




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!