Archived
1
0
This commit is contained in:
2025-10-24 17:20:56 +08:00
Unverified
parent acc0c9e220
commit e0fbc20716
21 changed files with 0 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
using System;
using static System.Math;
namespace C_Sharp_1_3
{
public class Program
{
static void Main()
{
Console.WriteLine("请输入变量x的值:");
double x = double.Parse(Console.ReadLine());
double y;
// 单句单分支方法
y = Log(-5 * x) + 6 * Sqrt(Abs(x) + Exp(4)) - Pow((x + 1), 3);
if (x>=0)
{
y = (Pow(x, 2) - 3 * x) / (Pow(x, 2) + 1) + 2 * PI + Sin(x);
}
Console.WriteLine("方法一,x={0},y={1}",x,y);
// 两句单分支方法
if (x >= 0)
{
y = (Pow(x, 2) - 3 * x) / (Pow(x, 2) + 1) + 2 * PI + Sin(x);
}
if(x < 0)
{
y = Log(-5 * x) + 6 * Sqrt(Abs(x) + Exp(4)) - Pow((x + 1), 3);
}
Console.WriteLine("方法二,x={0},y={1}", x,y);
// 双分支方法
if (x >= 0)
{
y = (Pow(x, 2) - 3 * x) / (Pow(x, 2) + 1) + 2 * PI + Sin(x);
}
else
{
y = Log(-5 * x) + 6 * Sqrt(Abs(x) + Exp(4)) - Pow((x + 1), 3);
}
Console.WriteLine("方法三,x={0},y={1}",x,y);
// 条件运算符方法
y = (x >= 0) ? (Pow(x, 2) - 3 * x) / (Pow(x, 2) + 1) + 2 * PI + Sin(x) : Log(-5 * x) + 6 * Sqrt(Abs(x) + Exp(4)) - Pow((x + 1), 3);
Console.WriteLine("方法四,x={0},y={1}",x,y);
}
}
}