Initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>C_Sharp_1_3</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36616.10 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C Sharp 1_3", "C Sharp 1_3.csproj", "{F4C49F99-3163-4F59-A9C9-DE459FA38244}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F4C49F99-3163-4F59-A9C9-DE459FA38244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F4C49F99-3163-4F59-A9C9-DE459FA38244}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F4C49F99-3163-4F59-A9C9-DE459FA38244}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F4C49F99-3163-4F59-A9C9-DE459FA38244}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {ED18AC2B-9EF6-468F-ACCB-466A5CF892F1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user