-1
I’m doing exercises on Uri online Judge, this asks:
In this problem you should read a number, indicating a row of the matrix on which an operation must be performed, a capital character, indicating the operation that will be performed, and all the elements of a matrix M[12][12]
.
Then calculate and show the sum or the mean of the elements that are in the green area of the matrix, as the case may be. The first input line contains an L number indicating the line that will be considered for operation. The second input line contains a single Uppercase character T (’S' or’M'), indicating the operation (Sum or Average) to be performed with the matrix elements.
Follow the 144 floating point values that make up the matrix, and it is filled line by line, from line 0 to line 11, always from left to right.
Exit
Print the requested result (sum or average) with 1 box after decimal point.
#include <stdio.h>
main() {
float M[12][12];
int linha, l, coluna;
char T;
float calculo;
scanf("%d", &l);
scanf("%c", &T);
for(linha = 0; linha < 12; linha ++){
for(coluna = 0; coluna < 12; coluna ++){
scanf("%f", &M[linha][coluna]);
}
}
if (T == 'M'){
for(coluna = 0; coluna < 12; coluna ++){
calculo = calculo + M[l][coluna];
}
calculo = calculo/12;
}
else {
for (coluna = 0; coluna < 12; coluna ++){
calculo = calculo + M[l][coluna];
}
}
printf ("%0.1f", calculo);
}
The program does not read the matrix and gives error. I thank anyone who wants to help me, thank you :)
Is that language? Look whenever possible to identify which language is the question.
– user28595
Looks like C. But that’s not enough
– Nuno Pereira
Sorry guys, it’s in C language
– Karen Santos