Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- minMaxRep(int a[], size_t size, int* min, size_t** cMin, int& max, size_t*& cMax)
- {
- int tempMin = a[0];
- int tempMinCount = 1;
- int tempMax = a[0];
- int tempMaxCount = 1;
- for(int i = 1; i < size; i++)
- {
- if(a[i] < tempMin)
- {
- tempMin = a[i];
- tempMinCount = 1;
- continue;
- }
- if(a[i] == tempMin)
- tempMinCount++;
- if(a[i] > tempMax)
- {
- tempMax = a[i];
- tempMaxCount = 1;
- continue;
- }
- if(a[i] == tempMin)
- tempMaxCount++;
- }
- *min = tempMin;
- max = tempMax;
- *cMax = tempMaxCount;
- **cMin = tempMinCount;
- }
- int main()
- {
- int tablica[20];
- srand(static_cast<unsigned>(time(NULL)));
- for(int i = 0; i < 20; ++i)
- {
- tablica[i] = rand() % 100;
- cout << tablica[i] << " ";
- }
- cout << endl;
- size_t* ccMin = new size_t;
- int* min = new int;
- size_t** cMin = &ccMin;
- int max;
- size_t* cMax = new size_t;
- minMaxRep(tablica, 20, min, cMin, max, cMax);
- cout << *min << endl;
- cout << **cMin << endl;
- cout << max << endl;
- cout << *cMax << endl;
- delete min;
- delete ccMin;
- delete cMax;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement