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
instead of initizaling the array to size [100], why not initialize the array to size [n] after user inputs it?
size of an array should only be in integer guys… that’s it…. it cannot be used as
[n]
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.
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.. 🙂
ya ya.. i agree this… super..
perfect answere
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.
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
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:)
why should we give condition in for loop as “j<n-i" why dont just "j<n"
Cause the last “i” spaces on your array are already ordered.
thnx v much
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
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.