Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SumaB
- {
- class Program
- {
- static void Main(string[] args)
- {
- double x, eps, term, sum = 0;
- int n = 0;
- // Въвеждане на x
- Console.Write("Въведете x: ");
- x = double.Parse(Console.ReadLine());
- // Въвеждане на допустимата грешка eps
- do
- {
- Console.Write("Въведете eps (например 0.0001): ");
- eps = double.Parse(Console.ReadLine());
- } while (eps <= 0 || eps >= 1);
- // Първи член
- term = x;
- // Сумиране на реда
- while (Math.Abs(term) >= eps)
- {
- sum += term;
- n++;
- term = Math.Pow(-1, n) * Math.Pow(x, 2 * n + 1) / Factorial(2 * n + 1);
- }
- // Резултат и проверка
- Console.WriteLine($"Резултат y = {sum}");
- Console.WriteLine($"Контролна стойност с Math.Sin(x) = {Math.Sin(x)}");
- }
- // Метод за пресмятане на факториел
- static long Factorial(int n)
- {
- long result = 1;
- for (int i = 2; i <= n; i++)
- result *= i;
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment