Q:

C Program to Sort Array in Ascending Order

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program to Sort Names in Alphabetical Order... >>
<< C Program to Sort n Numbers using Bubble Sort...