作业帮 > 综合 > 作业

编程题 计算分段函数sign(x)的值

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/13 10:22:33
编程题 计算分段函数sign(x)的值
y=sign(x)=-1 x
double 是双精度的浮点型数据,输出使用 %lf格式声明.
另外如果为了减少程序执行多分支流程,建议 swich case 进行分支处理,这样可以只走一个分支,而不是你现在的走三个if 分支.
switch ( ) {
case this-value:
Code to execute if == this-value
break;
case that-value:
Code to execute if == that-value
break;
...
default:
Code to execute if does not equal the value following any of the cases
break;
}