1
Contextualizing: I have an exercise that suggests creating a program to read student grades and show grades equal or higher than average.
Thus, the following code was written:
#include <stdio.h>
int main(){
float media;
float alunos[5];
int posicao;
float soma=0;
for(posicao=0;posicao<5;posicao=posicao++)
{
scanf("%f", &alunos[posicao]);
soma=soma+alunos[posicao];
}
media=soma/5;
for(posicao=0;posicao<5;posicao++)
{
if(alunos[posicao] >= media)
printf("%.2f \n", alunos[posicao]);
}
return 0;
}
First doubt: Why when the third parameter of the repeating structure is equal posicao++
it exceeds the limit that should be 5?
Exchanging the value that generated the first doubt for another equivalent posicao=posicao+1
, in the construction of the code.
Second question: Why are the notes larger or equal to the average not returned? If typed for example, 1, 2, 3, 4, 5, the sum would be 15 and the average 3, therefore the numbers 3, 4 and 5 should be displayed but are not.
There is, yeah! Got it. Thanks for the help bro!
– JoaoVSBraz