分段函数方程
程序代码
#include <stdio.h>
#include <math.h>
/*
*csdn学院——2016级
*文件名称:Myfun25.c
*作者:小臣小仁
*完成日期:2016年11月6日
*问题描述:从键盘输入x的值(要求为实型),
*根据公式1计算并输出x和y的值。
*/
int main()
{
float x,y;
printf("请输入x的值\n");
scanf("%f",&x);
if(x<2)
y=x;
else if(x<6)
y=x*x+1;
else if(x<10)
y=sqrt(x+1);
else
y=1/(x+1);
printf("y=%.4f",y);
return 0;
}
输出结果
知识点总结:
运用多分枝语句来对这x在四个值域的表达式求解,但x满足那个条件就执行那条的表达式,最后输出表达式的值。
心得体会
学会了如何运用if多分枝语句编程分段函数
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)