Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
904 B
2
Indexable
Never
//Estructura WHILE (Transcripción del código)
//Ejercicio 5

#include <iostream>
#include <cmath>

using namespace std; 

int main() {
    int count = 0;
    double number, sum = 0, product = 1, harmonicSum = 0;

    cout << "Introduce los números uno por uno y escribe 999 para terminar:" << endl; // ahora podemos usar cout y endl sin std::

    while (true) {
        cin >> number; 
        if (number == 999) break;

        sum += number;
        product *= number;
        harmonicSum += 1 / number;
        count++;
    }

    double arithmeticMean = sum / count;
    double geometricMean = pow(product, 1.0 / count);
    double harmonicMean = count / harmonicSum;

    cout << "Media Aritmética: " << arithmeticMean << endl;
    cout << "Media Geométrica: " << geometricMean << endl;
    cout << "Media Armónica: " << harmonicMean << endl;

    return 0;
}
Leave a Comment