Advertisement
Lavig

Лабораторна робота №8 (Завдання 3)

Nov 4th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     SetConsoleOutputCP(1251);
  8.     auto const n{ 13 };
  9.     float D[n] = { 5, -6, 24, -9.8, 15.3, 45, -6.23, 7, 2, -7, 54.1, 12.2, -23 }, sum{}, product{ 1 }, length{}, arithmetic_mean{}, geometric_mean{};
  10.     int i{};
  11.     for (i = 0; i <= n - 1; i++) {
  12.         if (D[i] > 0) {
  13.             sum += D[i];
  14.             product *= D[i];
  15.             length += 1.0;
  16.         }
  17.     }
  18.     arithmetic_mean = sum / length;
  19.     geometric_mean = pow(product, 1 / length);
  20.     cout << "Середнє арифметичне - " << arithmetic_mean << endl;
  21.     cout << "Середнє геометричне - " << geometric_mean << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement