Bubble sort descending order #include"stdio.h" int main() { int a[100],n,l,k,swap; printf("Enter the of Elements:"); scanf("%d",&n); for(k=0;k<n;k++) { printf("Enter a[%d] :",k); scanf("%d",&a[k]); } printf("Elements are :\n "); for(k=0;k<n;k++) { printf("%d\t",a[k]); } // sorting // for(k=0;k<n;k++) { for(l=0;l<n;l++) { if(a[l]<a[l+1]) { swap = a[l+1]; a[l+1]= a[l]; a[l]=swap; } } } printf("\nDescending order are:\n"); for(k=0;k<n;k++) { printf("%d \t",a[k]); } } Output are: Enter the of Elements:5 Enter a[0] :12 Enter a[1] :987 Enter a[2] :456 Enter a[3] :320 Enter a[4] :72 Elements are : 12 987 456 320 72 Descending order are: 987 456 320 72 12
The site contents Educational regarding C language.