0
I hosted the code complete in the Pastebin: https://pastebin.com/feKaxAiz. It is a matrix where it is possible to perform the SUMMING UP or AVERAGE of the elements above the MAIN DIAGONAL. It is rather extensive, but the first problem is in the MAIN, in the scanf of "OP", which references the operation the user wants to perform. I read with %c and he just ignore the scanf, ending the program, however, if I use %s, it allows OP reading and program works normally.
int main(){
int l, c;
int matriz[MAXL][MAXC];
numLC(&l, &c);
leMatriz(matriz, l, c);
printMatriz(matriz, l, c);
int soma = 0, media, cont = 0;
char OP;
printf("\nescolha uma operacao p/ ser feita com os elementos acima da DIAGONAL PRINCIPAL.\nS = soma | M = media: ");
scanf("%c", &OP);
somaUpDP(matriz, l, c, &soma, &cont);
//printf("\nsoma teste = %d", soma);
//printf("\nnum elementos teste = %d", cont);
operacao(OP, soma, cont);
return 0;
I would like an explanation p/ this. Besides, I’d like to know how the INCREMENT on a pointer. In function somaUpDP (summing the elements above the main diagonal), I use the pointer *cont to store both elements above D.P and thus be able to average.
void somaUpDP(int matriz[][MAXC], int l, int c, int *soma, int *cont){ //realiza a soma dos elementos ACIMA da DIAGONAL PRINCIPAL.
for(int i = 0; i < l; i++){
for(int j = 0; j < c; j++){
if(j > i){
*soma+=matriz[i][j]; //soma os elementos acima da D.P.
*cont = *cont + 1; //pega o tanto de elementos acima da D.P (necessário p/ média).
//*cont++ não funciona (?).
}
}
}
I tried to count using the operator ++ increment in shape *cont++, but it didn’t work.