Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace lilpumpik
  8. {
  9.     class Program
  10.     {
  11.         static int Factorial(int i)
  12.         {
  13.             int result;
  14.             if (i == 1)
  15.                 return 1;
  16.             result = Factorial(i - 1) * i;
  17.             return result;
  18.         }
  19.         static double Count(int n, int x)
  20.         {
  21.             double y = 0;
  22.             for(int i=1;i<=n;i++)
  23.             {
  24.                 y = y + Math.Pow(x, 2 * i - 1) / Factorial(i);
  25.             }
  26.             return y;
  27.         }
  28.         static int Test()
  29.         {
  30.             string str = Console.ReadLine();
  31.             int x;
  32.             while (!int.TryParse(str, out x))
  33.             {
  34.                 Console.WriteLine("Ошибка, вводимое значение должно быть числом");
  35.                 Console.WriteLine("Повторите ввод");
  36.                 str = Console.ReadLine();
  37.             }
  38.             return x;
  39.         }
  40.         static void Main(string[] args)
  41.         {
  42.             string answer;
  43.             int n;
  44.             int x;
  45.             do
  46.             {
  47.                 Console.WriteLine("Введите количество сумм: ");
  48.                 n = Test();
  49.                 Console.WriteLine("Введи Х: ");
  50.                 x = Test();
  51.                 Console.WriteLine(Count(n, x));
  52.                 Console.WriteLine("Повторить расчет? Да/Нет");
  53.                 answer = Console.ReadLine();
  54.             }
  55.             while (answer == "Да" || answer == "да");
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement