编写程序,求下面数列的前10项的和,结果保留2位小数.-sin(1!),sin(2!),-sin(3!),...,(-1

编写程序,求下面数列的前10项的和,结果保留2位小数.-sin(1!),sin(2!),-sin(3!),...,(-1)^n×sin(n!) (
-极端hh- 1年前 已收到1个回答 举报

anyway44 幼苗

共回答了25个问题采纳率:100% 举报

你要用什么语言写的呢?我用c#写了一个,程序如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int Factorial(int n) //求n的阶乘
{
if (n == 0 || n == 1)
return 1;
else
return n * Factorial(n - 1);
}
static void Main(string[] args)
{
double sum = 0;
for (int i = 1; i <= 10; i++)
{
sum += Math.Pow(-1, i) * Math.Sin(Program.Factorial(i));
}
Console.WriteLine(sum.ToString());
Console.Read();
}
}
}
运行结果如图,保留两位小数的话结果是-2.27

1年前

6
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.013 s. - webmaster@yulucn.com