Fandom

Scratchpad

PLE:Unidad5Ejercicio1

215,688pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

/*
Programa:       Unidad5Ejercicio01.cpp
Descripción:    Declara un array de 10 enteros y muestra el mayor, el menor
                la suma y la media aritmética.
*/
#include <iostream>
#include <cstdlib>
using namespace std;

void main ()
{
        const int MAX = 10;
        int num[MAX], max, min, suma = 0, i;
        float media = 0.0;

        // Leemos los elementos
        for(i = 0; i < MAX; i++)
        {
                cout << "Introduzca elemento " << i << ": ";
                cin >> num[i];
        }

        // Calculamos max, min, y suma
        max = min = suma = num[0];

        for(i = 1; i < MAX; i++)
        {
                if(num[i] > max)
                        max = num[i];
                if(num[i] < min)
                        min = num[i];
                suma += num[i];
        }

        // Calculo de la media
        media = (float) suma / MAX;

        // Mostramos resultados
        cout << "El maximo es = " << max << endl;
        cout << "El minimo es = " << min << endl;
        cout << "La suma es = " << suma << endl;
        cout << "La media es = " << media << endl;

        cin.ignore();
        cin.get();
}

Also on Fandom

Random wikia