//_10_else-if语句
//_10_main.cpp
//本例原题:
/*有一个分段函数,y=f(x),当x小于6时,y=x-12;
当x大于等于6且小于15时,y=5x+9;
当x大于等于15时,y=5x+9;
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,y;
printf("请输入自变量x:");
scanf("%d",&x);
if(x<6)
{
y = x - 12;
printf("x = %d , y = %d\n",x,y);
}
else if(x<15)
{
y = 3*x - 1;
printf("x = %d , y = %d\n",x,y);
}
else
{
y = 5*x + 9;
printf("x = %d , y = %d\n",x,y);
}
system("pause");
return 0;
}
10_else-if语句
最新推荐文章于 2023-04-14 14:01:14 发布