I have one array and I need to sort numbers in that array in groups. For example if I have 9 numbers and my P is 3 I need to sort three numbers in descending order then another 3 and another 3.
Example:
123 124 125 222 223 224 333 334 335
M is number of groups and P is amount of numbers in group. if M is 3 and P is also 3 it needs to give answer like
125 124 123 224 223 222 335 334 333
This is what I came up with but it doesn't work.
void sortgroup(int M, int P, int A[i])
{
      int c, d, swap, z = 0;
      for (c = z ; c < ( P*M - 1 + z ); c++)
      {
        for (d = z ; d < P + z - 1; d++)
        {
          if (A[d] < A[d+1])
          {
            swap       = A[d];
            A[d]   = A[d+1];
            A[d+1] = swap;
          }
        }
      z = P + z;
      }
}
 
    