Username77177

Nure-Programming-ControlWork1E2-6

Oct 25th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. namespace ControlWork1
  3. {
  4.     public class Secondexercise
  5.     {
  6.         public static void sec_ex()
  7.         {
  8.             //Задание 2
  9.             double sum = 0;
  10.             Console.WriteLine("Введите значение n: ");
  11.             double it = Convert.ToInt32(Console.ReadLine());
  12.             for (double n = it; n >= 1; n--)
  13.             {
  14.                 double b = 1;
  15.                 //(-1)^n
  16.                 double a = Math.Pow(-1,n);
  17.  
  18.                 //n!
  19.                 double i1 = n;
  20.                 while (i1 != 1)
  21.                 {
  22.                     b *= i1; // 1 * n * (n-1) * (n-2) * (n-3).. * 1 = n!
  23.                     i1--;
  24.                 }
  25.  
  26.                 sum += a/b;
  27.             }
  28.  
  29.             Console.WriteLine("Сумма ряда ((-1)^n)/n! = " + sum + ", при n = " + it);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment