Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <functional>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- vector <int> v, t(10);
- vector <int> ::iterator imax, pos;
- int n = 10;
- // Формування вектора
- for (int i = 0; i < n; ++i)
- v.push_back(rand() % 90 - 2);
- cout << "Sformovanuj vector\n" << endl;
- for (pos = v.begin(); pos != v.end(); ++pos)
- cout << *pos << " " << endl;
- imax = max_element(v.begin(), v.end());
- cout << "\nMax element: " << *imax << endl;
- // Визначення позиції максимального елемента
- imax = find(v.begin(), v.end(), *imax);
- cout << "Pozuciya max elementa: " << imax - v.begin() << endl;
- for (int i = 0; i < n; i++) {
- if (v[i] == 0){
- int leftPart = 1;
- int rightPart = 1;
- if(i > 0){
- leftPart = v[i-1];
- }
- if(i != n-1){
- rightPart = v[i+1];
- }
- cout << "Dobutok both parts = " << leftPart*rightPart << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement