//建控制台应用程序,利用下面的公式计算q的近似值,并运行出k=10时q的值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
//计算n的阶乘
public static int Factorial(int n)
{
int result = 1;
for (int i = n; i >= 1; i--)
{
result *= i;
}
return result;
}
public static void Main(string[] args)
{
int k = 10;
double q = 0;
if (k == 0)
Console.WriteLine("计算结果为:0");
else
{
for (int i = 0; i <= k; i++)
q += (double)1 / (double)Factorial(i) + (double)i * i;
Console.WriteLine("计算结果为:{0:F3}", q);
}
}
}
}
创建控制台应用程序,利用下面的公式计算q的近似值,并运行出k=10时q的值。
最新推荐文章于 2022-09-20 13:15:09 发布