Printing positions in field for same numbers, c language

You should:

  • Allocate an array to store all min/max positions.
  • Remove all elements and store new position if the record is breaked.
  • Add new position to the list if the record is tie.

It will be like this (only max is shown, min can also be done like this):

int pole[100], x;
int i, max_poses[100], max_pos_count = 0, max = 0;

/* read things to pole and x */

max = pole[0];
max_poses[0] = 0;
max_pos_count = 1;
for (i = 1; i < x; i++) {
    if (pole[i] > max) {
        /* the record is broken */
        max = pole[i];
        max_poses[0] = i;
        max_pos_count = 1;
    } else if (pole[i] == max) {
        /* tie */
        max_poses[max_pos_count++] = i;
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top