下面这个微机原理编程题怎么做、、急求答案?

假设有8位带符号数X,Y编程完成下列等式(要求各段定义完整) X+2 (X>0) Y={ X (X=0) X*10(X<0)

哪种语言??c++:#include<iostream.h>
void main()
{
float x; //定义x 为单精度浮点型
cout<<"please input x:"; //提示用户输入x
cin>>x; //输入x
if(x>0) //选择判断
{cout<<"y="<<x+2<<endl;}
else if (x==0)
{cout<<"y="<<x<<endl;}
else if(x<0)
{cout<<"y="<<x*10<<endl;}
else
{cout<<"not a number !!!"<<endl;}
} vb:Private Sub Form_Activate()
Dim x! ' 定义x为单精度浮点型
x = InputBox("please input a number") ‘ 从用户输入x
If x > 0 Then
Print x + 2
ElseIf x = 0 Then
Print x
Else
Print x * 10
End If
End Sub ’ 因为定义为单精度型输入其他字母符号等会出错
温馨提示:答案为网友推荐,仅供参考
相似回答