Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- #define VARIANT 1
- #define ARRSIZE 10*VARIANT
- void swap(float* a, float* b) {
- float* temp = a;
- a = b;
- b = temp;
- }
- float** minmax(float arr[], float* min, float* max, int n) {
- min = max = arr;
- for (float* cur = arr; n; ++cur, --n) {
- min = *min > *cur ? min = cur : min;
- max = *max < *cur ? max = cur : max;
- }
- std::swap(*min, *max);
- float** x = new float*[2]{ min,max };
- return x;
- }
- int main() {
- srand(time(NULL));
- float arr[ARRSIZE];
- float *min = nullptr, *max = nullptr;
- for (int i = 0; i < ARRSIZE;) {
- for (int ii = 0; ii < 10; ++i, ++ii) {
- arr[i] = rand() % 99 + 1;
- cout << setw(4) << arr[i] << ' ';
- }
- cout << setw(0) << endl;
- }
- float** result = minmax(arr, min, max, sizeof(arr) / sizeof(float));
- cout << "min: " << *result[0] << endl;
- cout << "max: " << *result[1] << endl;
- for (int i = 0; i < ARRSIZE;++i) {
- cout << setw(4) << arr[i] << ' ';
- }
- cout << setw(0) << endl;
- delete[] result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement