Answer the question
In order to leave comments, you need to log in
How to calculate the geometric mean of the values in 3 different arrays?
Develop a function that finds the geometric mean of all negative elements of arrays A(12), B(10), C(8), values are set from the keyboard or randomly (it doesn't matter)
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int A = 12,
B = 10,
C = 8;
int* arrA = new int[A];
for (int i = 0; i < A; i++) {
cin >> arrA[A];
}
cout << endl;
int* arrB = new int[B];
for (int i = 0; i < B; i++) {
cin >> arrB[B];
}
cout << endl;
int* arrC = new int[C];
for (int i = 0; i < C; i++) {
cin >> arrC[C];
}
cout << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
So I solved this task, everything works correctly (As far as I managed to check), I didn’t write very cleanly, so there are a lot of variables without which I think I could do without.
Here is the solution:
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
const int A = 12;
const int B = 10;
const int C = 8;
double ka = 0,kb=0,kc=0;
double a1 = 1, a = 0, b = 0, c = 0, b1 = 1, c1 = 1;
double crA = 0, crB = 0, crC=0,crABC=0;
int* arrA = new int[A];
int* arrB = new int[B];
int* arrC = new int[C];
cout << "Введите элементы массива A " << endl;
for (int i = 0; i < A; i++) {
cin >> arrA[i];
if (arrA[i] < 0) {
++ka;
}
}
for (int j = 0; j < A; j++) {
if (0 > arrA[j]) {
a =arrA[j];
a1 *= a;
}
}
ka = 1 / ka;
crA = pow(a1, ka);
cout << "Введите элементы массива Б " << endl;
for (int i = 0; i < B; i++) {
cin >> arrB[i];
if (arrB[i] < 0) {
++kb;
}
}
for (int j = 0; j < B; j++) {
if (0 > arrB[j]) {
b = arrB[j];
b1 *= b;
}
}
kb = 1 / kb;
crB = pow(b1, kb);
cout << "Введите элементы массива C " << endl;
for (int i = 0; i < C; i++) {
cin >> arrC[i];
if (arrC[i] < 0) {
++kc;
}
}
for (int j = 0; j < C; j++) {
if (0 > arrC[j]) {
c = arrC[j];
c1 *= c;
}
}
kc = 1 / kc;
crC = pow(c1, kc);
crABC = pow(crA * crB * crC,1.0/3.0);
cout << "Среднее геометрическое всех отрицательных элементов в этих массивах = " << crABC << endl;
}
You have already asked.
If I understand correctly, you need to put all these values \u200b\u200bof 3 arrays into one common array and then calculate the geometric mean or sum it up at the end one at a time
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question