Program to sort an array


Consider the following code to sort an array of elements:

CODE:

# include <stdio. h>

# include <conio. h>

void sort (int *a, int b);

void main ()

{

  int x [5], y, z;

  clrscr ();

  printf (“Enter 5 numbers”);

  for (y = 0; y < 5; y ++)

  {

    scanf (“%d”, &x [y]);

  }

 sort (x, 5);

 getch ();

}

void sorting(int *a, int b)

{

  int i, j, temp;

  for (i = 1; i <= y – 1; i ++)

  {

    for (j = 0; j < y – i; j++)

    {

      if (* (a + j) >* (a + j + 1))

      {

        temp = *(a + j);

        *(a + j) = *(a + j + 1);

        *(a + j + 1) = temp;

      }

    }

  }

  for (i = 0; i < 5; i ++)

  {

    printf (“%d”,* (a + i));

  }

}

OUTPUT:

Enter 5 numbers 14 23 56 3 2

2 3 14 23 56