Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace lilpumpik
- {
- class Program
- {
- static int Factorial(int i)
- {
- int result;
- if (i == 1)
- return 1;
- result = Factorial(i - 1) * i;
- return result;
- }
- static double Count(int n, int x)
- {
- double y = 0;
- for(int i=1;i<=n;i++)
- {
- y = y + Math.Pow(x, 2 * i - 1) / Factorial(i);
- }
- return y;
- }
- static int Test()
- {
- string str = Console.ReadLine();
- int x;
- while (!int.TryParse(str, out x))
- {
- Console.WriteLine("Ошибка, вводимое значение должно быть числом");
- Console.WriteLine("Повторите ввод");
- str = Console.ReadLine();
- }
- return x;
- }
- static void Main(string[] args)
- {
- string answer;
- int n;
- int x;
- do
- {
- Console.WriteLine("Введите количество сумм: ");
- n = Test();
- Console.WriteLine("Введи Х: ");
- x = Test();
- Console.WriteLine(Count(n, x));
- Console.WriteLine("Повторить расчет? Да/Нет");
- answer = Console.ReadLine();
- }
- while (answer == "Да" || answer == "да");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement