Vla_DOS

lr1_Z3

Jun 6th, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. // Дана послідовність з n цілих чисел. Знайти суму парних елементів цієї послідовності.
  2.  
  3. #include <iostream>
  4. #include <ctype.h>
  5. #include <fstream>
  6. #include <string>
  7. #include <sstream>
  8. #include <list>
  9. #include <math.h>
  10. using namespace std;
  11.  
  12. int main(void) {
  13.     setlocale(0, "");
  14.     int n;
  15.     cin >> n;
  16.     int* array = new int[n];
  17.     int sum = 0, i;
  18.     for (i = 0; i < n; i++)
  19.     {
  20.         array[i] = rand() % 50;
  21.     }
  22.  
  23.     for (i = 0; i < n; i++)
  24.     {
  25.         if (array[i] % 2 == 0)
  26.             sum += array[i];
  27.     }
  28.     for (i = 0; i < n; i++)
  29.     {
  30.         cout << array[i] << " ";
  31.     }
  32.     cout << "\nСума парних чисел = " << sum << endl;
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment