How can I turn it into C language?
How can I turn it into C language?
The function M, which you put, is a real function of two real variables, defined by collage (the expression used to calculate M (MP, ML) depends on the values of MP and ML).
For a real function of two real variables, a function C that models such a mathematical function can have as a signaturefloat nome_da_funcao(float arg1, float arg2)
, where arg1
and arg2
are function variables (in this case, MP
and ML
).
Depending on the desired precision (number of decimal places after the comma or, in C, after the period), you may have to use double
, but in this particular case, float
appears to be good.
As it is defined by collage, the expression to return its calculated value in (MP, ML) (or, if you like math, the image of (MP, ML)) depends on a conditional expression applied to the arguments MP and ML. Well, if the expression used to calculate the value of the function at the point (MP, ML) depends on whether MP and ML satisfy a certain condition, it is clear that you will have to use in your code a conditional, at least, or more than one , when applicable.
For your role:
if (MP
The complete program looks like this:
#include <stdio.h>
int main(){
double mp, ml;
printf("Digite o Mp: ");
scanf("%d",&mp);
printf("\nDigite o Ml: ");
scanf("%d",&ml);
while(mp<5 || ml<5){
printf("\nMp ou Ml menor que 5,0. Digite o numero novamente");
printf("Digite o Mp: ");
scanf("%d",&mp);
printf("\nDigite o Ml: ");
scanf("%d",&ml);
}
int m;
//função:
m=(7*mp+3*ml)/10;
printf("%d", m);
}