axeefectushka

Untitled

Feb 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1.  
  2. #include "pch.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. void EnterArray(int *, int);
  7. void Display(int *, int);
  8. int sum(int *, int);
  9. int mult(int &, int);
  10.  
  11. int main()
  12. {
  13.     int n;
  14.     cout << "Enter the size of array: ";
  15.     cin >> n;
  16.     int *a = new int[n];
  17.     EnterArray(a, n);
  18.     Display(a, n);
  19.     int s = sum(a, n);
  20.     cout << "Sum = " << s << endl;
  21.     int m = mult(*a, n);
  22.     cout << "Mult = " << m << endl;
  23.     return 0;
  24. }
  25. void EnterArray(int *a,int n)
  26. {
  27.     cout << "Enter elements: ";
  28.     for (int i = 0; i < n; i++)
  29.     {
  30.         cin >> a[i]; cout << " ";
  31.     }
  32.     cout << endl;
  33. }
  34. void Display(int *a, int n)
  35. {
  36.     cout << "Your array: ";
  37.     for (int i = 0; i < n; i++)
  38.     {
  39.         cout << a[i] << " ";
  40.     }
  41.     cout << endl;
  42. }
  43. int sum(int *a, int n)
  44. {
  45.     int s = 0;
  46.     for (int i = 0; i < n; i++)
  47.     {
  48.         if(a[i]>0)
  49.         s += a[i];
  50.     }
  51.     return s;
  52. }
  53. int mult(int &a,int n)
  54. {
  55.     int m = 1;
  56.     int *temp = &a;
  57.     for (int i = 0; i < n; i++)
  58.     {
  59.         if (temp[i] < 0)
  60.             m *= temp[i];
  61.     }
  62.     return m;
  63. }
Add Comment
Please, Sign In to add comment