C Program to Display Array Elements in Ascending Order

C Program to Display Array Elements in Ascending 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 5 3 2 10 11 18 75 39 22 78 14 25 16 78 93 73 17 90
Entered elements are:1  4       5       3       2       10      11      18      75      39      22      78      14
25      16      78      93      73      17      90

Elements in Ascending form:1    2       3       4       5       10      11      14      16      17      18      22
25      39      73      75      78      78      90      93

 

You may also like...

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.