Initial commit
This commit is contained in:
10
cs3/C_Sharp_3_1/C_Sharp_3_1.csproj
Normal file
10
cs3/C_Sharp_3_1/C_Sharp_3_1.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs3/C_Sharp_3_1/C_Sharp_3_1.sln
Normal file
25
cs3/C_Sharp_3_1/C_Sharp_3_1.sln
Normal file
@@ -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_3_1", "C_Sharp_3_1.csproj", "{E11A2FAE-3F54-48C2-86B8-3AB7BFC20869}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E11A2FAE-3F54-48C2-86B8-3AB7BFC20869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E11A2FAE-3F54-48C2-86B8-3AB7BFC20869}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E11A2FAE-3F54-48C2-86B8-3AB7BFC20869}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E11A2FAE-3F54-48C2-86B8-3AB7BFC20869}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F31B64FE-9C56-4D0A-9ACD-B8037F502CA0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
36
cs3/C_Sharp_3_1/Program.cs
Normal file
36
cs3/C_Sharp_3_1/Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
namespace C_Sharp_3_1
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
int n = -1, result = 1, i = 1;
|
||||
Console.WriteLine("请输入一个正整数n");
|
||||
while (n < 0)
|
||||
{
|
||||
n = int.Parse(Console.ReadLine());
|
||||
}
|
||||
// For循环实现阶乘
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
result *= i;
|
||||
}
|
||||
Console.WriteLine("for 循环 {0}!={1}", n, result);
|
||||
// while循环实现阶乘
|
||||
while (n > 1)
|
||||
{
|
||||
result *= n;
|
||||
n--;
|
||||
}
|
||||
Console.WriteLine("while 循环 {0}!={1}", n, result);
|
||||
//do...while循环实现阶乘
|
||||
do
|
||||
{
|
||||
result *= i;
|
||||
i ++;
|
||||
} while (i<=n);
|
||||
Console.WriteLine("do...while 循环 {0}!={1}", n, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user