Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/C Sharp 1_3/Program.cs
2025-10-24 17:19:46 +08:00

48 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}