current position:Home>The C language piecewise function y = f (x) can be expressed as: 2x + 1 (X & lt; 0) y = 0 (x = 0) 2x-1 (X & gt; 0) programming to input an x value and output the y value corresponding to the function.

The C language piecewise function y = f (x) can be expressed as: 2x + 1 (X & lt; 0) y = 0 (x = 0) 2x-1 (X & gt; 0) programming to input an x value and output the y value corresponding to the function.

2022-01-26 23:02:04 CSDN Q & A

1、 Piecewise functions y=f(x) Can be expressed as :2x+1(x<0)y=0(x=0)2x-1(x>0) Programming to enter a x value , Corresponding to output function y value .




Refer to the answer 1:
#include <stdio.h>double fun(double x){    double y;    if(x<0)        y = 2*x+1;    else if(x==0)        y = 0;    else        y = 2*x-1;    return x;}int main(){    double x,y;    scanf("%lf",&x);    y = fun(x);    printf("%lf",y);    return 0;}



Refer to the answer 2:



Refer to the answer 3:
//2x+1(x<0)y=0(x=0)2x-1(x>0)#include <stdio.h>int main(){    float x,y;    scanf("%f",&x);    if(x<0)        y = 2*x+1;    else if(x==0)       y = 0;    else       y = 2*x-1;    printf("%f",y);    return 0;}



Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262302020858.html

Random recommended