Advertisement
Razk2108

FUNCIONES CON ARREGLOS

Oct 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. void poblarArreglo(int arr[],int n){
  6.     for(int i=0;i<n;i++){
  7.         arr[i]=rand()%(10-99+1)+10;
  8.     }
  9. }
  10. void mostrarArreglo(int arr[],int n){
  11.     for(int i=0;i<n;i++){
  12.         cout<<arr[i]<<endl;
  13.     }
  14. }
  15. float promedio(int arr[],int n){
  16.     int suma=0;
  17.     for(int i=0;i<n;i++){
  18.         suma+=arr[i];
  19.     }
  20.     return suma*1.0/n;
  21. }
  22. int main(){
  23.     srand(time(NULL));
  24.     int numeros[9];
  25.     poblarArreglo(numeros,9);
  26.     cout<<"Los numeros aleatorios son: "<<endl;
  27.     mostrarArreglo(numeros,9);
  28.     cout<<"El promedio es: "<<promedio(numeros,9);
  29.     return 0;
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement