#include #include int main(int argc, char* argv[]) { #define MAX_A_SIZE 10 // size of the array where decimal values of arguments will be managed int num[MAX_A_SIZE]; int element, max, min, posmax, posmin; int numElements = 0; // check that too many arguments are not passed if (argc - 1 > MAX_A_SIZE) { printf("Too many parameters. Maximum parameters number is %d\n", MAX_A_SIZE); exit(1); // exit the program with retcode 1 ==> error } else numElements = argc - 1; // initialize num array elements to 0 for (int i = 0; i < MAX_A_SIZE; i++) { num[i] = 0; } //print the number of arguments passed to the the program printf("List of %d elements:\t", numElements); //initialize variables that will contain maximum and minumum values passed as arguments max = INT_MIN; min = INT_MAX; for (int i = 1; i <= numElements; i++) { printf("\t%s", argv[i]); //conversion of the string value of the arguments to the decimal one and store it in num array elements num[i - 1] = (int)strtol(argv[i], (char**)NULL, 10); // check if max and min variables values shall be updated according to the ith value of the arguments if (num[i - 1] > max) { max = num[i - 1]; posmax = i; } if (num[i - 1] < min) { min = num[i - 1]; posmin = i; } } //print max and min value in the arguments list and their position in the arguments list printf("\nMax value %d in position %d.\tMin value %d in position %d.\n", max, posmax, min, posmin); num[posmax-1] = num[numElements - 1]; num[numElements - 1] = max; num[posmin-1] = num[0]; num[0] = min; // order the list in ascending order, there can be many other solutions to reach the same outcome bool ordered = true; do { ordered = true; for (int i = 1; i < numElements - 1; i++) { if (num[i] > num[i + 1]) { element = num[i]; num[i] = num[i + 1]; num[i + 1] = element; ordered = false; } } } while (!ordered); // print the ordered list printf("Ordered list:\t"); for (int i = 0; i < numElements; i++) { printf("\t%d", num[i]); } printf("\n"); exit(0); }