Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Дана послідовність з n цілих чисел. Знайти суму парних елементів цієї послідовності.
- #include <iostream>
- #include <ctype.h>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <list>
- #include <math.h>
- using namespace std;
- int main(void) {
- setlocale(0, "");
- int n;
- cin >> n;
- int* array = new int[n];
- int sum = 0, i;
- for (i = 0; i < n; i++)
- {
- array[i] = rand() % 50;
- }
- for (i = 0; i < n; i++)
- {
- if (array[i] % 2 == 0)
- sum += array[i];
- }
- for (i = 0; i < n; i++)
- {
- cout << array[i] << " ";
- }
- cout << "\nСума парних чисел = " << sum << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment