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 laba_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- Task1 t1 = new Task1();
- Task2 t2 = new Task2();
- Console.WriteLine("Введите номер задания");
- int z = Convert.ToInt32(Console.ReadLine());
- switch (z)
- {
- case (1):t1.Calculate(Convert.ToInt32(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()));
- break;
- case (2): t2.IncSum(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()));
- break;
- }
- Console.ReadKey();
- }
- }
- class Task1
- {
- static int factorial(int i)
- {
- int result;
- if (i == 1)
- return 1;
- result = factorial(i - 1) * i;
- return result;
- }
- public double t1(int n)
- {
- double result = (Math.Pow((-1), n)) / factorial((n + 1));
- return result;
- }
- public double Calculate(int n, double m)
- {
- double sum = 0;
- for (int i = n; i <= m; i++)
- {
- sum += t1(i);
- }
- Console.WriteLine(sum);
- return sum;
- }
- }
- class Task2
- {
- public double IncSum(int a, int b)
- {
- int temp_a = a, temp_b = b;
- if (a == 0)
- {
- return b;
- }
- else if (b == 0)
- {
- return a;
- }
- if (a != temp_a + temp_b)
- {
- IncSum(a += 1, b -= 1);
- }
- if (a == temp_a + temp_b)
- {
- Console.WriteLine(a);
- }
- return a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement