Home > Back-end >  Circulation structure in the application of piecewise function how to evaluate value of y?
Circulation structure in the application of piecewise function how to evaluate value of y?

Time:12-13

Known x keyboard input by the user, calculate the following section function y value
Y=x2 + 10 (x <5)
Y=(x + 1) * (x + 5) <=(- 5 x <0)
Y=x (x=0)
Y=x - 2 (0 Y=x + 25 (x>=10)
Out, I want to use the if the else structure found that logic is wrong, who can type the complete code, I compare,

CodePudding user response:

If you can, take explanation, by the way

CodePudding user response:

Reference:
 # include 
Int main (int arg c, char * argv [])
{
Float x, y;
Printf (" input x: ");
The scanf (" % f ", & amp; X);
If (x<5)
{
X + y=x * 10;
Printf (" y=% f \ n ", y);
}
If (x & gt;=5 & amp; & X & lt; 0)
{
Y=(x + 1) * (x + 5) + 0.000000001;//to avoid - 0.00
the condition of thePrintf (" y=% f \ n ", y);
}
If (x==0)
{
Y=x;
Printf (" y=% f \ n ", y);
}
If (x> 0 & amp; & x<10)
{
Y=x - 2;
Printf (" y=% f \ n ", y);
}
If (x>=10)
{
Y=x + 25;
Printf (" y=% f \ n ", y);
}
system("pause");
return 0;
}

CodePudding user response:

refer to the second floor QZJHJXJ response:
for reference:
 # include 
Int main (int arg c, char * argv [])
{
Float x, y;
Printf (" input x: ");
The scanf (" % f ", & amp; X);
If (x<5)
{
X + y=x * 10;
Printf (" y=% f \ n ", y);
}
If (x & gt;=5 & amp; & X & lt; 0)
{
Y=(x + 1) * (x + 5) + 0.000000001;//to avoid - 0.00
the condition of thePrintf (" y=% f \ n ", y);
}
If (x==0)
{
Y=x;
Printf (" y=% f \ n ", y);
}
If (x> 0 & amp; & x<10)
{
Y=x - 2;
Printf (" y=% f \ n ", y);
}
If (x>=10)
{
Y=x + 25;
Printf (" y=% f \ n ", y);
}
system("pause");
return 0;
}

Thank you, after I find the wrong place
  • Related