Problems with averages

Asked

Viewed 60 times

0

I need to insert 3 notes, average with 3 notes, then with the highest note and the second highest note , then with the highest note and the worst note.

#include<stdio.h>
int meio(int a, int b, int c)
{
    if(a>b && a<c)
    return a;
    else
    return b,c;
}
int menor (int a, int b, int c)
{
if (a<b && a<c)
return a;
else
return b,c;

}
int maior (int a, int b, int c)
{
if (a > b && a>c)
 return a;
else
 return b,c;  
}
main()
{
float M,MDM;
int n1,n2,n3;
printf("\n primeira nota: ");
scanf("%d",&n1);
printf("\n segunda nota: ");
scanf("%d",&n2);
printf("\n terceira nota: ");
scanf("%d",&n3);
printf("\n Maior nota = %d",maior(n1,n2,n3));
printf("\n Menor nota = %d",menor(n1,n2,n3));
printf("\n Segunda maior nota=%d",meio(n1,n2,n3));
M=(n1+n2+n3)/3;
printf("\n media:%.2f",M);
}

  • What is your difficulty? Because you entered your code and what should be done but did not specify what you got stuck on. Edit your answer to get more detailed so we can help you out.

  • then , I can’t separate the second highest note , I get the highest and the lowest , but not the second highest and I need to average the highest and lowest note , the highest and the second highest and dps of the 3 .

  • i was up there trying to put as if it were the second largest:int middle(int a, int b, int c) { if(a>b && a<c) Return a; Else Return b,c; }

  • 1

    What do you think return b,c; would make?

  • Already tried to sort the three notes and then do m=(a+b+c)/3;, x=(a+b)/2;, y=(a+c)/2; and z=(b+c)/2;?

  • but as the program will separate the average of the highest notes , and the largest with the lowest ?

  • Sorting the notes. If the first is larger than the second, you exchange the first with the second. If the first is larger than the third, you trade the first with the third. If the second is bigger than the third, you trade the second with the third.

Show 2 more comments

1 answer

0

In charge return b, c;, the comma operator returns only the last element separated by the comma, and therefore has no logical meaning in your program. For example, in the function maior, instead of being return b, c;, the largest of the two should be calculated.

int maior (int a, int b, int c){
    if (a > b && a > c) return a;
    if (b > a && b > c) return b;
    return c;   
}

Use the same logic for functions menor and meio and your program will work.

  • caracaaaa , vlwww manoo !!! now was , now I just have to think about how to do the average , but already helped a lot ! thank you very much !

  • You’ve already managed to average the three notes using M = (n1+n2+n3)/3;. Because the average between two notes is the sum of the notes divided by 2, and you already have to take the value of the highest note and the worst note (ie calling the function maior and menor), just use the same procedure.

  • i know how to put in printf , but I don’t know how to put as formula , pq when I put as formula I can only organize Mem=(n1+N2)/2

  • in the printf I know that at the end I have to put -> ("...",minor (n1,N2,N3),major(n1,N2,N3));

  • You can store the value of the function in a variable, for example, maiorNota = maior(n1, n2, n3);, create other variables for the lowest note and for the middle note and then use them in the average formula.

  • 1

    Bro, it worked perfectly! I don’t know how to thank you , having a lot of difficulty to learn programming , I was a while without practicing because my notebook gave problem and I ended up getting confused in the matter. But mttt thanks and sorry for anything !

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.