/****************************************************
* EJERCICIO 301 *
* AUTOR: Th3_Cr0w *
****************************************************/
#include <iostream.h>
#include <stdlib.h>
int main()
{
float numero, mayor, menor, suma, media;
int i;
cout << endl; // El primer numero se introduce
cout << " Introduce un numero (1/10): "; // fuera del bucle para
cin >> numero; // inicializar el menor,
// el mayor y la suma.
menor = numero; // Si no se hiciera, al llegar
mayor = numero; // al bucle no podrían compararse.
suma = numero;
for(i = 1; i < 10; i++)
{
cout << " Introduce un numero (" << i+1 << "/10): ";
cin >> numero;
if(numero < menor)
menor = numero;
if(numero > mayor)
mayor = numero;
suma += numero;
}
media = suma/10;
cout << endl;
cout << " RESULTADOS:\n";
cout << " Mayor: " << mayor << endl;
cout << " Menor: " << menor << endl;
cout << " Suma: " << suma << endl;
cout << " Media: " << media << endl << endl;
system("PAUSE");
return 0;
}
#include <stdio.h>
#include <windows.h>
int iArray[10],iMay=0,iMen,iSum=0,iMed,iCon;
int main(void)
{
for(iCon=0;iCon<=9;iCon++)
{
printf("Digita valor %d: ",iCon+1);
scanf("%d",&iArray[iCon]);
}
for(iCon=0;iCon<=9;iCon++)
{
if(iArray[iCon]>=iMay)
{
iMay=iArray[iCon];
}
iSum=iSum+iArray[iCon];
iMed=iSum/10;
}
iMen=iMay;
for(iCon=0;iCon<=9;iCon++)
{
if(iArray[iCon]<=iMen)
{
iMen=iArray[iCon];
}
}
printf("\nEl mayor es: %d",iMay);
printf("\nEl menor es %d",iMen);
printf("\nLa suma es: %d",iSum);
printf("\nLa Media es: %d",iMed);
Sleep(5000);
}
Los que habeis hecho me parecen mucho mas complicados que :
#include <cstdlib>
#include <iostream>
using namespace std;
int menor,mayor,media,suma;
int mayorN(int a, int b)
{
if ( a > b )
{ mayor=a;
}
else
{mayor=b;
}
}
int menorN(int a, int b)
{
if ( a < b )
{menor = a;
}
else
{menor = b;
}
}
int num,a;
int main(int argc, char *argv[])
{
for ( int i=0; i < 11; i++)
{
cout << "introduce un numero" << endl;
cin >> num;
suma = suma + num;
mayorN(mayor,num);
menorN(menor, num);
}
media= suma / 10;
cout << "La suma vale " << suma << "la media " << media << endl;
cout << "El mayor numero es" << mayor << " y el menor" << menor << endl;
system("PAUSE");
return EXIT_SUCCESS;
}