Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- void EnterArray(int *, int);
- void Display(int *, int);
- int sum(int *, int);
- int mult(int &, int);
- int main()
- {
- int n;
- cout << "Enter the size of array: ";
- cin >> n;
- int *a = new int[n];
- EnterArray(a, n);
- Display(a, n);
- int s = sum(a, n);
- cout << "Sum = " << s << endl;
- int m = mult(*a, n);
- cout << "Mult = " << m << endl;
- return 0;
- }
- void EnterArray(int *a,int n)
- {
- cout << "Enter elements: ";
- for (int i = 0; i < n; i++)
- {
- cin >> a[i]; cout << " ";
- }
- cout << endl;
- }
- void Display(int *a, int n)
- {
- cout << "Your array: ";
- for (int i = 0; i < n; i++)
- {
- cout << a[i] << " ";
- }
- cout << endl;
- }
- int sum(int *a, int n)
- {
- int s = 0;
- for (int i = 0; i < n; i++)
- {
- if(a[i]>0)
- s += a[i];
- }
- return s;
- }
- int mult(int &a,int n)
- {
- int m = 1;
- int *temp = &a;
- for (int i = 0; i < n; i++)
- {
- if (temp[i] < 0)
- m *= temp[i];
- }
- return m;
- }
Add Comment
Please, Sign In to add comment