Created
March 19, 2020 16:50
-
-
Save zafe/9eb8009a8b1796dece669ac38c176850 to your computer and use it in GitHub Desktop.
Ejercicio con matrices y funciones en C++
This file contains hidden or 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> | |
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