#include <stdio.h>

int main()
{
    int num, N[10], x, y, z, temp;

    printf("How many number would you like to sort : ");
    scanf("%d", &num);
    printf("Input the %d numbers :\n", num);

    for (x = 0; x < num; x++)
        scanf("%d", &N[x]);

    for (x = 0; x < num; x++)
    {
        for (y = 0; y < num - x; y++)
        {
            if (N[x] > N[x + y])
            {
                temp = N[x];
                N[x] = N[x + y];
                N[x + y] = temp;
            }
        }

        printf("step %d : ", x + 1);
        for (z = 0; z < num; z++)
        {
            printf("%3d", N[z]);
        }
        printf("\n");
    }
}

Output:-

Enter How many Numbers : 10
Enter the 10 elements to be sorted:
5
6
9
4
2
1
0
6
7
8

The array of elements before sorting :
5 6 9 4 2 1 0 6 7 8
The array of elements after sorting :
0 1 2 4 5 6 6 7 8 9

Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post