2
I’m having a question about the conditional test to store the lowest value, it’s not really a doubt, the problem is that when it prints, the value of the lowest value is 0.0, which hurts to calculate the average correctly, the highest value worked, but the smallest not, which could be?
#include <stdio.h>
#define NUM 5
int main(){
int i, j;
float notas[NUM];
float media;
float maior=0, menor=0;
for(i=0; i<NUM; i++){
scanf("%f", ¬as[i]);
}
for(i=0; i<NUM; i++){
if(notas[i] >= notas[i+1]){
maior = notas[i];
}
else{
maior = notas[i+1];
}
}
for(i=0; i<NUM; i++){
if(notas[i] < notas[i+1]){
menor = notas[i];
}
else{
menor = notas[i+1];
}
}
for(i=0; i<NUM; i++){
media += notas[i];
}
media -= maior;//cálculo da média da escola
printf("%.1f %.1f %.1f\n", maior, menor, media);
printf("\n");
for(i=0; i<NUM; i++){
printf("%.1f ", notas[i]);
}
return 0;
}
This average calculation doesn’t make sense, that’s right?
– Maniero
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero