编程问题:y=x (-5<x<0);y=x-1 (x=0);y=x+1 (0<x<10)编写程序输出x,y的值。
3个回答
2013-11-14
展开全部
//C++: if语句:#include <iostream>using namespace std;
int main(){
int x=0,y=0;
cin>>x;
if(x>-5&&x<0) y=x;
else if(x>0&&x<10) y=x+1;
else if(x==0) y=x-1;
cout<<"x = "<<x<<" y = "<<y<<endl;
return 0;
}
//switch语句:#include <iostream>using namespace std; int main(){
int x=0,y=0;
cin>>x;
switch(x)
{
case -4:
case -3:
case -2:
case -1: y=x;break;
case 0: y=x-1;break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: y=x+1;break;
default:
cout<<"X值超出界限!"<<endl;
}
cout<<"x = "<<x<<" y = "<<y<<endl;
return 0;
}
int main(){
int x=0,y=0;
cin>>x;
if(x>-5&&x<0) y=x;
else if(x>0&&x<10) y=x+1;
else if(x==0) y=x-1;
cout<<"x = "<<x<<" y = "<<y<<endl;
return 0;
}
//switch语句:#include <iostream>using namespace std; int main(){
int x=0,y=0;
cin>>x;
switch(x)
{
case -4:
case -3:
case -2:
case -1: y=x;break;
case 0: y=x-1;break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: y=x+1;break;
default:
cout<<"X值超出界限!"<<endl;
}
cout<<"x = "<<x<<" y = "<<y<<endl;
return 0;
}
2013-11-14
展开全部
if语句
if(x>-5&&x<0)
y=x;
else if(x==0)
y=x-1;
else if(x>0&&x<10)
y=x+1;
if(x>-5&&x<0)
y=x;
else if(x==0)
y=x-1;
else if(x>0&&x<10)
y=x+1;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-14
展开全部
switch(x){case 0:y=x-1;break;default: if(x>-5 && x<10){ if(x<0) y=x; if(x>0) y=x+1; }}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询