diff --git a/Pi/App.config b/Pi/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/Pi/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Pi/Pi.csproj b/Pi/Pi.csproj new file mode 100644 index 0000000..c18f472 --- /dev/null +++ b/Pi/Pi.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {0FB17AAF-16C4-4AEE-A1F9-F272C407F57A} + Exe + Properties + ConsoleApplication2 + ConsoleApplication2 + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Pi/Program.cs b/Pi/Program.cs new file mode 100644 index 0000000..a91b3f8 --- /dev/null +++ b/Pi/Program.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApplication2 +{ + class Program + { + static void Main(string[] args) + { + while (true) + { + //π/4 = 1 -1/3 +1/5 -1/7 +1/9 -1/11 +……,精确至少4位小数. + Console.WriteLine("请输入运算次数进行下一次计算..."); + decimal a = decimal.Parse(Console.ReadLine()); + Console.WriteLine("输入的次数: {0}", a); + decimal result = 0; + bool add = true; + for (decimal i = 1; i < a; i += 2) + { + //result += 1d / (2d * i - 1d) * Math.Pow(-1d, i - 1d); + if (add) + { + result += 1m / i; + add = false; + } + else + { + result -= 1m / i; + add = true; + } + //Console.WriteLine(result * 4d); + } + Console.WriteLine("PI的结果为: {0}", (result * 4m)); + Console.WriteLine("PI的结果为: {0}", (result * 4m).ToString("#0.0000")); + } + } + } +} diff --git a/Pi/Properties/AssemblyInfo.cs b/Pi/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..31e6b59 --- /dev/null +++ b/Pi/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ConsoleApplication2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ConsoleApplication2")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("33e1a85c-b1a1-4ba9-b8af-b7f2a45e2bde")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/水仙花数字/App.config b/水仙花数字/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/水仙花数字/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/水仙花数字/Program.cs b/水仙花数字/Program.cs new file mode 100644 index 0000000..0ced277 --- /dev/null +++ b/水仙花数字/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApplication1 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("100到999之内的水仙花数为: "); + for (int i = 100; i < 1000; i++) + { + //int a = i / 100; + //int b = (i - a * 100) / 10; + //int c = i - a * 100 - b * 10; + int a = i / 100; //百位数字 + int b = i % 100 / 10; //十位数字 + int c = i % 10; //个位数字 + if (i == a * a * a + b * b * b + c * c * c) + { + Console.WriteLine("{0}*{0}*{0} + {1}*{1}*{1} + {2}*{2}*{2} = {3}", a, b, c, i); + } + } + Console.WriteLine("按任意键退出..."); + Console.ReadLine(); + } + } +} diff --git a/水仙花数字/Properties/AssemblyInfo.cs b/水仙花数字/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3b4bd78 --- /dev/null +++ b/水仙花数字/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过以下 +// 特性集控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ConsoleApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ConsoleApplication1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 使此程序集中的类型 +// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, +// 则将该类型上的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("25ace4af-2a1b-4e5d-affe-057b5e2262f0")] + +// 程序集的版本信息由下面四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, +// 方法是按如下所示使用“*”: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/水仙花数字/水仙花数字.csproj b/水仙花数字/水仙花数字.csproj new file mode 100644 index 0000000..d504062 --- /dev/null +++ b/水仙花数字/水仙花数字.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {91A7507F-1204-44CA-8D3E-C813FAA0DC07} + Exe + Properties + ConsoleApplication1 + ConsoleApplication1 + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file