编程求下面分段函数的值(其中自变量x的值由键盘输入。使用if…else if...
include<stido.h>#include<math.h>int main(){float x,y;printf("请输入一个数:");scanf(“%f”,&x);if(x<0)y=x*x;else if(x>0) y=sinx; else y=1-2*x; printf("%f",y); return 0; }
C语言,分别用if 语句和switch语句编写程序求分段函数的值
define a 10 \/\/a自己取值 void main(){ float x, y;scanf("%f",&x);if(x>=0.5 && x<1.5)y = a*x*x;if(x>=1.5 && x < 3.5)y = exp(a*x);if(x<=3.5 && x<7.5)y = pow(sin(a+x), 2);printf("%f", y);} \/\/switch语句 include <stdio.h> include <...
求大神指导用Java编程求分段函数(要求用if…else语句实现)
import java.util.Scanner;public class App65 {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);System.out.println("请输入x值:");int x = scanner.nextInt();int y = 0;if (x < 0) {y = x * x;} else if (x >= 0 && x < 10) {y ...
C语言程序设计,计算下列分段函数。
if(x>=0&&y>0)printf("x=%f,y=%f,f(x)=%f",x,y,(2*x*x+3*x+1\/(x+y)));else if(x>=0&&y<=0)printf("x=%f,y=%f,f(x)=%f",x,y,(2*x*x+3*x+1\/(1+2*y)));else printf("x=%f,y=%f,f(x)=%f",x,y,(3*sin(x+y)\/(2*x*x+3*x+1)));} ...
C语言,求分段函数的值
include<stdio.h> include<math.h> void main(){ double x,y;while(scanf("%lf",&x)!=EOF){ if(x>=0.5&&x<1.5)y=a*x*x;else if(x>=1.5&&x<3.5)y=exp(a*x);else if(x>=3.5&&x<7.5)y=pow(sin(a+x),2);printf("y=%.3lf\\n",y);} } \/\/话说a是什么 ...
用C语言的if语句,描述下面分段函数的计算
if(x<0) y=sin(x);else y=exp(x);\/\/fun就是你要的函数 include <stdio.h> include <math.h> double fun(int x){ if( x<0 )return sin(x);else return exp(x);} int main(int argc, char *argv[]){ printf("%f\\n", fun(-45));printf("%f\\n", fun(1));return 0;}...
c语言求下面的分段函数,多种方法
3多分支if语句 include <stdio.h> void main(){ int x,y;printf("Please type in x:");scanf("%d",&x);if(x<0)y=x;else if(x<10)y=x-10;else y=x+10;printf("y=%d\\n",y);} 2嵌套的if语句 include <stdio.h> void main(){ int x,y;printf("Please type in x:");...
编程,计算下列分段函数值: x2+3x-4,x<0且x≠-4 f(x)= x2-6x+5,0=x...
include <stdio.h>int main(){ double x; double fx; printf("请输入x的值:"); scanf("%lf",&x); if(x<0&&x!=-4) { fx = x*x + 3*x - 4; } else if((x==0||x<10)&&x!=1&&x!=5) { fx = x*x - 6*x + 5; } else...
C语言计算分段函数
1. 代码如下,3)需要实际运行时输入测试 int main(void){ double x, y, f;printf("Please input 2 double number in the form of x y:\\n");scanf("%lf%lf", &x, &y);if(x>=0 && y>0)f = 2*x*x + 3*x +1\/(x+y);else if(x>=0 && y<=0)f = 2*x*x + 3*x...
用matlab求分段函数值
这样:clc,clear,close all x = -5:.1:5;y(x>=1) = 3.*x(x>=1).^2+1;y(x>-1 && x<1) = 0;y(x<=-1) = -x(x<=-1).^3+2;figure,plot(x,y)