Fandom

Scratchpad

PLE:Unidad4Ejercicio01

216,226pages 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:         Unidad4Ejercicio01.cpp
Fecha:            21/11/2006
Descripción:      Lee un array y muestra el menor, el mayor y la media.

*/
#include <iostream>
#include <conio>
using namespace std;

const int NUM = 10;

void main()
{
      int num[NUM], i, may, men, sum=0;
      float med;

      // Leemos el array y calculamos la suma
      for(i = 0; i < NUM; i++)
      {
            // Leemos
            cout << "Introduzca numero ";
            cin >> num[i];
            // Calculamos la suma
            sum += num[i];
      }

      // Media aritmética
      med = (float) sum / NUM;

      // Calculamos el mayor y el menor
      may = men = num[0];
      for(i = 1; i < NUM; i++)
      {
            if(num[i] > may)
                  may = num[i];
            if(num[i] < men)
                  men = num[i];
      }

      // Mostramos los resultados
      cout << "\nEl mayor es = " << may;
      cout << "\nEl menor es = " << men;
      cout << "\nLa suma es = " << sum;
      cout << "\nLa media aritmetica es = " << med;

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

Also on Fandom

Random wikia