According to the website http://www.matematica.pt/faq/numero-par.php:
"First the definition of PAR number can only be applied to integers. That being said, a number is even if when divided by the number two, the result is an integer number. Using mathematical language, "even is every number that can be written in the form 2n", with n belonging to the set of integers"
So 8 is even because 2 x 4 = 8.
One way to analyze this in programming is through the widely used MOD function or Rest of the entire division. If the rest of a number divided by two is zero(0) it will be even! Otherwise, if the rest of the whole division by 2 is different != of zero the number shall be odd.
See the code below. I made small modifications, study the code and try to do it yourself. Good Study
/*Calcula a media dos ímpares numa matriz que recebe números INTEIROS*/
#include <stdio.h>
#include <stdlib.h>
float mediaImpar(int a[4][4]); //protótipo da função
int main(int argc, char** argv) {
int numero, linha, coluna;
int matriz[4][4]; //declara uma matriz 4 x 4 com linhas e colunas 0,1,2 e 3
float media = 0.0;
for(linha = 0; linha < 4; linha++){
for(coluna = 0; coluna < 4; coluna++){
system("CLS"); //limpa a tela
printf("Entre com o elemento matriz[%d][%d]: ", linha+1, coluna+1);
scanf("%d", &matriz[linha][coluna]);
}//fim for
}//fim for
media = mediaImpar(matriz); //chama a função
printf("====A matriz digitada====\n\n");
for(linha = 0; linha < 4; linha++){
for (coluna = 0; coluna < 4; coluna++){
printf("%2d ", matriz[linha][coluna] );
if (coluna == 3)
printf ("\n");
} //fim for
} //fim for
printf("\nMedia dos números impares da matriz: %.2f",media);
return (EXIT_SUCCESS);
} //fim main
float mediaImpar(int a[4][4]){
int count = 0, i, j;
int soma = 0;
for(i = 0; i < 4; i++){
for(j = 0; j < 4; j++){
if(a[i][j] % 2 != 0){
soma += a[i][j]; // o mesmo que soma = soma + a[i][j];
count++;
}//fim if
}//fim for
}//fim for
float media = (float)soma/count; //cast para que o resultado da media seja float
return media;
} //fim mediaImpar
See the program output when running:
tried this too, has similar error. error: invalid operands to Binary % (have 'float' and 'double')
– Stelio Spallanzani
First explain to me what is a remnant of float. In mathematics this does not exist.
– Maniero