# C program to sort Array in descending order

This program is made in the C programming language.  Below is the code for the C program to sort the array in the descending order –

```/* C program to arrange or sort the array in the Descending order */
#include<stdio.h>
#include<conio.h>
void main()
{
int ar[100],j,n,i,tmp;

printf(" Enter the size of the array \t");
scanf("%d",&n);

printf("Now enter the elements in the array \t");
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}

printf("\n Array is - ");
for(i=0;i<n;i++)
{
printf("\t %d",ar[i]);
}

for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(ar[j]<ar[j+1])
{
tmp=ar[j+1];
ar[j+1]=ar[j];
ar[j]=tmp;
}
}
}

printf("\n\n Array in the Descending order is - \n");
for(i=1;i<=n;i++)
{
printf("\t %d",ar[i]);
}
getch();
}
```

Logic – This program uses the bubble sort technique to sort all the elements of the array in the descending order. Bubble sort technique uses the system of passes to sort the elements in the desired order. The number of passes is one less then the number of elements in the array. Passes, pass the elements of the array one by one in the desired order to sort the elements of array.

Input – Enter the size of the array -5
Array is -23   53   1   25   65

Output
Array in the descending order is – 65   53   25   23   1

#### 15 thoughts on “C program to sort Array in descending order”

1. jt says:

instead of initizaling the array to size [100], why not initialize the array to size [n] after user inputs it?

1. dd says:

size of an array should only be in integer guys… that’s it…. it cannot be used as
[n]

2. k says:

kk

Ideal Information, appreciate it. When it comes to customers which usually expect to get in shape really fast, consider our website for the best means by which to burn excess fat efficiently.

4. Aritra Ghosh says:

There is a bug in the code..
for(i=0;i<n;i++)
not "for(i=1;i<=n;i++)"
as array is default initialized to zero.. 🙂

1. dd says:

ya ya.. i agree this… super..

5. mandela says:

1. Lynsey says:

Using your logic (and I use that term loosely here), a company like Apple could totally sabotage an upcoming product release, in order to make a greater profit because they heavily shorted their company stock. Nevermind that they easily stand to profit more with a successful product reinvse.Neaermled that the damage to the company’s reputation easily outweighs any short-term profit that might be realized through a strategy such as this.

2. http://www./ says:

Que grande la recreativa del Afterburner, por aquella Ã©poca era algo de pelÃ­cula. Con el Sonic Blastman me reÃ­ mucho una vez que un colega iba ultra pedo y le diÃ³ por jugar, imaginaos el resto, sÃ³lo os digo que acabo abrazado a la almohadilla esa xD

3. http://www./ says:

Thank you Lakshmi for giving all the stitches in one single link.This will be very useful for those who missed the TAST 2010.I am still on the sewing schedule as I have a lot to stitch before March.So not much embroidery:)

6. sudheer says:

why should we give condition in for loop as “j<n-i" why dont just "j<n"

1. Clark says:

7. tejas says:

thnx v much

8. BestDarcy says:

I see you don’t monetize your website, don’t waste