3
#include <stdio.h>
int main()
{
double A, B;
double MEDIA;
scanf("%f", &A);
scanf("%f", &B);
MEDIA = (A + B)/2;
printf("MEDIA = %5f", MEDIA);
return 0;
}
In this program I have already understood that the problem is that the scanf()
cannot read variables double
. So, by changing the primitive type of variables A
and B
for float
, instead of double
, the program works correctly as it should. But I NEED you to read the variables in double
. I don’t know how to solve, I don’t even know if there’s any way to solve, since for some reason, I didn’t find anything talking about reading variables double
.
Interesting case that scanf() is different from printf(). In printf() the %f serves for the double by the fact that printf() accepts variable number of parameters, while scanf() uses different masks for float, double and long double.
– epx
Thank you very much @Maniero. Solved the problem that was in question. But do you believe that was not the problem to be solved in the exercise? I thought that was the problem, and even after I was able to solve this part, this was not the problem I was not allowed to pass in the exercise. But thank you so much anyway.
– GiovanePS
I also did not understand this part of it being necessary to read the variables in double, but since the exercise asks so, I will not doubt, kkkk.
– GiovanePS