C Program to Sort Array in Ascending Order

Sort Array in Ascending Order


Write a C Program to Sort Array in Ascending Order. Here’s simple C Program to Sort Array in Ascending Order in C Programming Language.


Below is the source code for C Program to Sort Array in Ascending Order which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C Program to Sort Array in Ascending Order  */

#include <stdio.h>
 
void main()
{
    int i, j, a, n, number[30];
 
    printf("Enter the value of N \n");
    scanf("%d", &n);
    printf("Enter the numbers \n");
    for (i = 0; i < n; ++i)
        scanf("%d", &number[i]);
    for (i = 0; i < n; ++i)
    {
        for (j = i + 1; j < n; ++j)
        {
            if (number[i] > number[j])
            {
                a =  number[i];
                number[i] = number[j];
                number[j] = a;
            }
        }
    }
    printf("The numbers arranged in ascending order are given below \n");
    for (i = 0; i < n; ++i)
        printf("%d\n", number[i]);
}

Output : : 


/*  C Program to Sort Array in Ascending Order  */

Enter the value of N
6
Enter the numbers
3
8
0
6
7
2
The numbers arranged in ascending order are given below
0
2
3
6
7
8

Above is the source code for C Program to SortArray in Ascending Order which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply