Answer the question
In order to leave comments, you need to log in
Where is the error in the code of exclusions?
Write a C# program that calculates the value of an expression using the for statement. It is forbidden to use the functions of the
Math class. Compare the calculated values of the expression with the values obtained using the check function.
Algorithm
code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab_08
{
class Program
{
static void Main(string[] args)
{
L:
Console.Write("x=");
double x = double.Parse(Console.ReadLine());
if (x <= -1 || x >= 1)
{
Console.WriteLine("Значення х не входить в промiжок вiд -1 до 1. Введiть ще раз"); goto L;
}
else
Console.Write("n=");
int n = int.Parse(Console.ReadLine());
double s = 1, c = 1;
for (int i = 1; i <= n; i++)
{
double v = 1;
for (double j = n - i + 1; i <= n; i++)
{
v = v * j;
}
c = c * x;
double f = 1;
for (int k = 1; k <= n; k++) f = f * k;
s = s + c * v / f;
}
double o = Math.Pow(1+x, n);
if (Math.Abs(s - o) < 1e-6)
{
Console.WriteLine("Результат: " + s);
}
Console.ReadLine();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question