C#编程求助:从键盘输入一个整数给变量x,若为负数,求出它的平方;若为正数,求出它的立方。

2025-05-05 07:47:30
推荐回答(4个)
回答1:

static void Main(string[] args)
{
int x;
int res;
x = Int32.Parse( Console.ReadLine());
if (x<0)
{
res = x * x;
}
else
{
res = x * x * x;
}
Console.WriteLine(res.ToString());
Console.ReadLine();
}

回答2:

int a;
if(X<0){
a=X*X
return a;
}if(X>0){
a=X*X*X
return a;
}

回答3:

if(x<0){
x=x*x;

}else{
x=x*X*X;

}

回答4:

int t;
if(t>0)
return t*t*t;
else
return t*t;