Created
March 27, 2016 21:40
-
-
Save h3ct0rjs/b80cb2c30ad98b5dd8f5 to your computer and use it in GitHub Desktop.
1.Obtener el promedio de datos de un vector.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm>//min function | |
using namespace std; | |
int main(){ | |
int n,suma; //tamaño del vector | |
cout<<"Inserte Tamaño para crear el Vector: \t"; | |
cin>>n; //almacenamos las n posiciones del vector. | |
int array[n]; //creamos el vector de n posiciones. | |
for(int i=0;i<n;i++) | |
array[i]=rand() % 100; //rellenamos con | |
//valores pseudoaleatorios el array. | |
cout<<"[*] El vector aleatorio es:\n"; //Lo imprimimos. | |
for(int j=0;j<n;j++) | |
cout<<" "<<array[j]; | |
///Esta parte inferior es el objetivo del ejercicio. | |
for(int i=0;i<n;i++) suma+=array[i]; | |
cout<<"\n[*] El Promedio es: "; //Lo imprimimos. | |
//pd: No es necesario usar double para la precision solo es preferencia mia. | |
cout<<double(double(suma)/double(n))<<endl; //uso double para obtener los decimales. | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment