Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //В одномерном массиве определить кол-во э-тов равных 0 и сумму после минимального э-та
- #include "pch.h"
- #include <iostream>
- #include "time.h"
- using std::cout;
- using std::cin;
- using std::endl;
- void InputOutput(int *a, int n)
- {
- for (int i = 0; i < n; i++) a[i] = rand() % 11;
- for (int i = 0; i < n; i++) cout << a[i] << endl;
- }
- void Solve(int *a, int n, int &z, int &r)
- {
- int min = 11,j=0;
- for (int i = 0; i < n; i++)
- {
- if (a[i] == 0) z += 1;
- if (min > a[i])
- {
- j = i;
- min = a[i];
- }
- }
- for (int i = 0; i < n; i++)
- if (i > j) r += a[i];
- }
- int main()
- {
- setlocale(0, "");
- srand(time(0));
- int n, z = 0, r = 0;
- cout << "Введите длину массива: "; cin >> n;
- int *a = new int[n];
- InputOutput(a, n);
- Solve(a, n,z,r);
- cout << "Кол-во э-тов равных 0: " << z << endl << "Сумма э-тов после минимального: " << r;
- delete[] a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement