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

admin has written 2 articles

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

    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:)

  1. BestDarcy says:

    I see you don’t monetize your website, don’t waste
    your traffic, you can earn additional bucks every month because you’ve
    got hi quality content. If you want to know how to make extra bucks, search
    for: Ercannou’s essential adsense alternative

  2. ThaliaJuicy says:

    I often visit your website and have noticed that
    you don’t update it often. More frequent updates will give your website higher
    authority & rank in google. I know that writing articles takes a
    lot of time, but you can always help yourself with miftolo’s tools which will shorten the
    time of creating an article to a couple of seconds.

Cancel reply

Leave a Reply to BestDarcy

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>