Advertisement
ULK

Лабораторная №9 (11.29)

ULK
Dec 4th, 2022 (edited)
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.  
  9.     cout << "Enter the number of elements" << endl;
  10.     cin >> n;
  11.  
  12.     int* A;
  13.     A = new int[n];
  14.     int sum = 0;
  15.     int sum2 = 0;
  16.     int i = 0;
  17.  
  18.     cout << "Enter the elements" << endl;
  19.     for (i = 0; i < n; i++) {
  20.         cin >> A[i];
  21.         sum = sum + A[i];
  22.         sum2 = sum2 + pow(A[i], 2);
  23.     }
  24.  
  25.     if (sum % 2 == 0) {
  26.         cout << "Sum of array elements is _even_" << endl;
  27.     }
  28.     else {
  29.         cout << "Sum of array elements is _odd_" << endl;
  30.     }
  31.  
  32.  
  33.     if (sum % 2 == 0) {
  34.         cout << "Sum^2 of array elements is _even_" << endl;
  35.     }
  36.     else {
  37.         cout << "Sum^2 of array elements is _odd_" << endl;
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement