A
A
Alexey2020-11-09 21:42:23
C++ / C#
Alexey, 2020-11-09 21:42:23

Answer -nan [inf] how to solve?

You need to calculate the geometric mean of the negative elements of the array.
First, I filled the array, counted as many such elements.

double a=0, a1=1;
for (int i=0; i<A;i++){
     if ( arrA[i]< 0) {
         a = arrA[i];
         a1 *= pow(a, 1/k);
}
где k - счётчик отрицательных элементов.

Everything is fine with the loop, but in a1 it prints -nan [ inf ] For example -2 cannot be raised to the power of 0.25...
I would be grateful for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-11-09
@resolut1123

For example -2 cannot be raised to the power of 0.25

And can you?
The geometric mean of negative numbers is not well defined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question