Skip to content

Instantly share code, notes, and snippets.

@zafe
Created March 19, 2020 16:50
Show Gist options
  • Save zafe/9eb8009a8b1796dece669ac38c176850 to your computer and use it in GitHub Desktop.
Save zafe/9eb8009a8b1796dece669ac38c176850 to your computer and use it in GitHub Desktop.
Ejercicio con matrices y funciones en C++
#include <iostream>
using namespace std;
float promedio();
int main()
{
cout<< "El promedio es " << promedio();
return 0;
}
float promedio(){
int i, j, contador = 0;
int matriz[2][2];
float acumulador = 0;
for(i=0;i<2;i++)
for(j=0;j<2;j++){
cout<<"Ingrese elemento ["<<i<<"]["<<j<<"]"<<endl;
cin>>matriz[i][j];
if(matriz[i][j] % 2 == 0 ) {
acumulador = acumulador + matriz[i][j];
contador++;
}
}
// cout << "acumulador" << acumulador << " contador: " << contador;
// cout << "division: " << acumulador / contador;
return acumulador / contador;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment