
#include <stdioh>
#include <mathh>
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%lf",&x);
y=x>=0sqrt(x):pow(x+1,2)+2x+1/x;
printf("f(%2f) = %2f\n", x, y);
}
}
这样:
clc,clear,close all
x = -5:1:5;
y(x>=1) = 3x(x>=1)^2+1;
y(x>-1 && x<1) = 0;
y(x<=-1) = -x(x<=-1)^3+2;
figure,plot(x,y)
扩展资料:
注意事项
语法
if expression
statements
end
描述
MATLAB计算表达式,如果产生一个逻辑真或者非零结果,然后就执行一条或者多条MATLAB命令语句。
当有嵌套if时,每一个if必须和一个相应的end匹配。
当你在if语句里面嵌套使用else if或者else时,一般的格式如下:
if expression1
statements1
elseif expression2
statements2
else
statements3
end
#include <iostream>
using std::cout;
using std::endl;
double gety(double x);
int main()
{
double x=3;
double y=gety(x);
cout<<y;
return 0;
}
double gety(double x){
if(x<0 && x>-10){
return x+1;
}else if(x==0){
return x-1;
}else if(x>0 && x<10){
return 2x+1;
}else{
return false;
}
};
#include <stdioh>
int main(void){
int x;
int y;
scanf("%d",&x);//得到x的值
if(x<1){
y=x;
}else if (x>=1&&x<12) {
y=5x-2;
}else {
y=8x-10;
}
printf("y= %d\n",y);
return 0;
}
以上就是关于C语言写计算分段函数全部的内容,包括:C语言写计算分段函数、用matlab求分段函数程序、编写程序 ,计算分段函数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)