根据以下函数关系对输入的每个x值求y值。用C++编写程序y=xx+2 2<x≤10y=2x -1x≤2y=x-1 x≤-1
#include
int main(){ float x,y; cout<<"请输入x的值:"; cin>>x; if(x>2 && x<=10){ y=x*(x+2); cout<<"y的值为:"<<y; } else if(x>-1 && x<=2){ y=2*x; cout<<"y的值为:"<<y; } else if(x<=-1){ y=x-1; cout<<"y的值为:"<<y; } else{ cout<<"输入有误!"; } return 0; }
原文地址: https://www.cveoy.top/t/topic/Nkv 著作权归作者所有。请勿转载和采集!