WEEK 1-piecewise Functions

Source: Internet
Author: User
/**ProgramCopyright and version description Section * copyright (c) 2012, Yantai University Computer college student * All rightsreserved. * file name: Fun. CPP * Author: Qiu xuewei * Completion Date: July 15, November 17, 2012 * version: V1.0 * description of the task and solution * input Description: function independent variable X * Problem description: evaluate the function value: when x <0.3, f (x) = 0; When 0.3 ≤ x ≤ 0.8, f (x) = (x-0.3)/(0.8-0.3 ); when x> 0.8, f (x) = 1; * program output: F (x) value */# include <iostream> using namespace STD; const double X1 = 0.3, x2 = 0.8; // two constants are defined as global constant variables, which is convenient and easy to maintain. Double F (double); // declare int main () {int X; cout <"Enter the value of X:" <Endl; CIN> X; cout <"solution: f (x) =" <F (x) <"\ n"; return 0;} double F (Double X) {double F; // you need to define the custom variable if (x <X1) f = 0; else if (x <= x2) F = (x-x1)/(x2-x1); elsef = 1; return F ;}

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.