Найти сумму ряда - C# (180798)
Формулировка задачи:
----------------
Программа вроде правильная. Нужно сделать по примеру.
Помогите пожалуйста.
----------------
---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
int point = 3; //число точек в которых следует вычислить функцию
double[] j = { 0.2, 0.6, 0.9 };
double eps = 1e-6;
//Цикл по расчетным точкам
for (int i = 0; i < point; i++)
{
//Вычислим y
double l = 1 / Math.Pow((1 + j[i]), 2);
// Вычисление частичной суммы ряда
int srok = 1; //число членов разложения
double sum = 1.0; //Cумма ряда
double arg = 1.0; // Член ряда
double x = 1;
while (Math.Abs(arg) > eps)
{
srok++;
x *= j[i];
arg = srok * x;
if (srok % 2 == 0)
{
arg = -arg;
}
sum += arg;
}
Console.WriteLine("Номер итерации = " + i + ";");
Console.WriteLine("X[" + i + "] = " + j[i] + ";");
Console.WriteLine("F(X[" + i + "]) = Y =" + l + ";");
Console.WriteLine("S(X[" + i + "]) = " + sum + ";");
if(sum>l)
Console.WriteLine("S(x)> F(x)");
else
Console.WriteLine("S(x)< F(x)");
Console.WriteLine("Количество членов ряда = " + srok + ";");
Console.WriteLine("\n");
}
Console.ReadKey(true);
}
}
}Пример
Решение задачи: «Найти сумму ряда»
textual
Листинг программы
using System;
class Program
{
public static void Main()
{
foreach (double x in new double[] { 0.2, 0.6, 0.9 })
{
double y = 1.0;
double z = 0.0;
for (int i = 1; Math.Abs(y) > 1e-6; i++)
{
z += y;
y *= x * (double)(i + 1) / (double)(-i);
}
Console.WriteLine(z);
}
}
}