C Program to Display Array Elements in Descending Order

C Program to Display Array Elements in Descending Order:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
    int a[20],i,j,temp=0,max=0,min=0;
    printf("Enter 20 elements in array\n");
    for(i=0;i<20;i++)
        scanf("%d",&a[i]);
    printf("Entered elements are:");
    for(i=0;i<20;i++)
        printf("%d\t",a[i]);
    printf("\nElements in Ascending form:");
    for(i=0;i<20;i++)
    {
        for(j=i+1;j<20;j++)
        {
            if(a[i]<a[j])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }

        }
    }
    for(i=0;i<20;i++)
    printf("%d\t",a[i]);
}

OUTPUT:

Enter 20 elements in array
1 4 7 3 6 5 8 1 22 78 44 22 36 87 41 25 74 95 25 91
Entered elements are:1  4       7       3       6       5       8       1       22      78      44      22      36
87      41      25      74      95      25      91
Elements in Ascending form:95   91      87      78      74      44      41      36      25      25      22      22
8       7       6       5       4       3       1       1

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.