9-degree OJ 1062 piecewise functions (simulation)

Source: Internet
Author: User

9-degree OJ 1062 piecewise functions (simulation)

Question 1062: piecewise Functions

Time Limit: 1 second

Memory limit: 32 MB

Special question: No

Submit: 2877

Solution: 1671

Description:

Compile a program and calculate the value of the following piecewise Function y = f (x.
Y =-x + 2.5; 0 <= x <2
Y = 2-1.5 (X-3) (X-3); 2 <= x <4
Y = x/2-1.5; 4 <= x <6

Input:

A floating point number N

Output:

There may be multiple groups of test data. For each group of data,
Output the piecewise function value corresponding to N: f (N ). The result is retained with three decimal places.

Sample input:
1
Sample output:
1.500
#include
            
             #include
             
              #include
              
               double y(double x){    double result;    if(0<=x&&x<2.0)    {        result=-1*x+2.5;    }    else if(2<=x&&x<4){        result=2-1.5*(x-3.0)*(x-3.0);    }    else{        result=x/2-1.5;    }    return result;}int main(int argc, char *argv[]){    freopen("1062.in", "r", stdin);    double N;    while(~scanf("%lf",&N))    {        printf("%.3lf\n",y(N));    }    return 0;}
              
             
            


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.