Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int* readArray(int &n);
- void calc(int *arr, int n, int &sum, int &count, int A);
- int main() {
- int n, A, count, sum;
- int* arr = readArray(n);
- cout << endl << "Enter A: ";
- cin >> A;
- cout << endl << "===RESULT===" << endl << endl;
- calc(arr, n, sum, count, A);
- if (count) {
- cout << "There are " << count << " elements which are divided into " << A << endl;
- cout << "Sum = " << sum << endl;
- } else {
- cout << "There are no elements which are divided into " << A << endl;
- }
- delete[] arr;
- return 0;
- }
- int* readArray(int &n) {
- cout << "Enter size of array: ";
- cin >> n;
- int* arr = new int[n];
- cout << "Enter " << n << " elems of array: ";
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- return arr;
- }
- void calc(int *arr, int n, int &sum, int &count, int A) {
- sum = count = 0;
- for (int i = 0; i < n; i++) {
- if (arr[i] % A == 0) {
- sum += arr[i];
- count++;
- }
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement