Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. //В одномерном массиве определить кол-во э-тов равных 0 и сумму после минимального э-та
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include "time.h"
  6. using std::cout;
  7. using std::cin;
  8. using std::endl;
  9.  
  10. void InputOutput(int *a, int n)
  11. {
  12. for (int i = 0; i < n; i++) a[i] = rand() % 11;
  13. for (int i = 0; i < n; i++) cout << a[i] << endl;
  14. }
  15.  
  16. void Solve(int *a, int n, int &z, int &r)
  17. {
  18. int min = 11,j=0;
  19. for (int i = 0; i < n; i++)
  20. {
  21. if (a[i] == 0) z += 1;
  22. if (min > a[i])
  23.  
  24. {
  25. j = i;
  26. min = a[i];
  27. }
  28. }
  29. for (int i = 0; i < n; i++)
  30. if (i > j) r += a[i];
  31. }
  32.  
  33. int main()
  34. {
  35. setlocale(0, "");
  36. srand(time(0));
  37. int n, z = 0, r = 0;
  38. cout << "Введите длину массива: "; cin >> n;
  39. int *a = new int[n];
  40. InputOutput(a, n);
  41. Solve(a, n,z,r);
  42. cout << "Кол-во э-тов равных 0: " << z << endl << "Сумма э-тов после минимального: " << r;
  43. delete[] a;
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement