Jump to content

Média de valores de ficheiro


Ana Silva
Go to solution Solved by rbsrbs_dev,

Recommended Posts

  • Solution

Olá Ana,

Como não partilhaste nenhum código é quase impossível saber precisamente qual é a dúvida.

Assumindo que tens um array de estruturas de alunos(?), só precisas de percorrer o array com um ciclo para somar as notas e por fim dividires pelo número de alunos.

E.g.:

int sum = 0;
for(int i = 0; i < alunos_count; i++) {
    sum += alunos[i].nota;
}

// Nota: cast de um dos valores caso queiras o resultado real 
float media = sum / (float)alunos_count;

printf("Media: %.2f\n", media);
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.