4
I have to do a program that will read 4 grades from each of the 6 students in a class and store them in a matrix NOTES[6][5]. For each student, the arithmetic mean of the 4 grades should be calculated and stored in the last column of the matrix (index column 4). The program should also print the average of each student and, finally, the arithmetic average of the class.
I made a code and went to execute, at the time of picking up STUDENT 6 GRADE 2, instead of being typed STUDENT 6, it types a totally random number, and ends the program, and depending, the code of the different errors!
What mistake I’m making?
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main() {
setlocale(LC_ALL, "Portuguese");
float nota[6][5], media;
int i, j;
media = 0;
for(i=1; i<=6; i++) {
for(j=1; j<=5; j++) {
printf("\nAluno %d Nota %d \n", i, j);
scanf("%f", ¬a[i][j]);
}
}
for(i=1;i<=6;i++)
{
for(j=1;j<= 5;j++) {
printf("%f", nota[i][j]);
}
printf("\n");
}
for(i=0; i<=6; i++) {
for(j=0; j<5; j++) {
nota[i][5] = nota[i][5] + nota[i][j];
}
}
for(i=0; i<=6; i++) {
nota[i][5] = nota[i][5]/4;
media = nota[i][5] + media;
}
media = media/6;
for(i=0; i<=6; i++) {
printf("\nA média do aluno %d = %.2f", i, nota[i][5]);
}
printf("\nA média dos alunos: %.2f", media);
return 0;
}
I packed up the for, and even so it is giving random numbers, and for all students, I used the same grade and gave different values and even and also using the %.2f for the average of all students, it seems that the formatting was annulled. Student average 0 = 3.75 Student average 1 = 11.25 Student average 2 = 15.25 Student average 3 = 20.75 Student average 4 = 16369920226015860000000000.00 Student average: 2728320037669310000000000.00
– Vagner Wentz