0
I have the following problem to solve: Write a program that reads two matrices of 10 rows and 2 columns. Each row of the matrix stores two notes of a student. The first matrix stores the notes of G1 and the second the grades of G2. After reading the two matrices calculate the final average of each of the students and store in a vector of 10 positions. Important the note average is arithmetic. Write the vector resulting on the screen. Important: the final note of G1 is obtained by averaging the two notes of the matrix G1. A G2 note is obtained from the average of the two notes in the matrix of G2.
I realized what was requested, however at the time of displaying the result of media[i]
only the value 0 is shown in all vector indices.
#include <stdio.h>
#include <string.h>
main()
{
int m1[10][2], m2[10][2];
int soma[10], soma2[10], media[10], result[10], result2[10];
int l, c, i, j;
printf ("\n Notas G1 \n");
for (l=0; l<10; l++)
{
for (c=0; c<2; c++)
{
printf ("\n Aluno [%d], nota [%d]: ", l+1,c+1);
scanf ("%d", &m1[l][c]);
soma[l] += m1[l][c]; //soma notas g1
result[l] = soma[l] / 2;
}
}
printf ("\n Notas G2 \n");
for (i=0; i<10; i++)
{
for (j=0; j<2; j++)
{
printf ("\n Aluno [%d], nota [%d]: ", i+1,j+1);
scanf ("%d", &m2[i][j]);
soma2[i] += m2[i][j]; // soma notas g2
result2[i] = soma2[i] / 2;
}
}
for (i=0; i<10; i++)
{
media[i] = (result[i] + result2[i])/2; //media
}
for (i=0; i<10; i++)
{
printf ("\n Media dos aluno [%d]: %.2f", i,media[i]);
}
}
How are the variables typing?
– André Lins