Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <cstdlib>
- #include <math.h>
- #include <ctime>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUS");
- srand( time_t (0));
- int i, i0=-1, f, n, min, max,sum=0;
- cout << "Введите количество элементов массива" << endl;
- cin >> n;
- int *arr = new int[n];
- if (n < 1 || n>20) {
- cout << "Ошибка,n не должен быть больше 20" << endl;
- system("pause");
- return 0;}
- cout << "1.Ввести самостоятельно" << endl;
- cout << "2.Рандомные числа" << endl;
- cin >> f;
- switch (f){
- case 1:
- for (i = 0; i < n; ++i) {
- cout << "a[" << i + 1 << "]=";
- cin >> arr[i];}
- break;
- case 2:
- for (i = 0; i < n; ++i) {
- arr[i] = rand() % 22 -0;
- cout<<arr[i]<<endl;}
- break;}
- int nom_max;
- min = max = arr[0];
- for (i = 0; i < n; ++i) {
- if (min > arr[i]) min = arr[i];
- else if (max < arr[i]) { max = arr[i]; nom_max = i; }
- }
- cout << "Min: " << min << endl;
- cout << "Max: " << max << endl;
- for (i = n - 1; i >= 0; --i)
- if (arr[i] == 0) {
- i0 = i;
- break;}
- if (i0 < 0) { cout << "Нулей нет" << endl;
- return 0;}
- if (i0 == n - 1) {
- cout << "Ноль последний" << endl;
- return 0;}
- if (nom_max > i0)
- {
- min = i0;
- max = nom_max;
- }
- else
- {
- max = i0;
- min = nom_max;
- }
- for (i = min+1; i <max; ++i) {
- sum += arr[i];}
- cout << "sum=" << sum << endl;
- delete[] arr;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement