Advertisement
RolexOsmiy

Untitled

Mar 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 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 laba_4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Task1 t1 = new Task1();
  14.             Task2 t2 = new Task2();
  15.             Console.WriteLine("Введите номер задания");
  16.             int z = Convert.ToInt32(Console.ReadLine());
  17.             switch (z)
  18.             {
  19.                 case (1):t1.Calculate(Convert.ToInt32(Console.ReadLine()), Convert.ToDouble(Console.ReadLine()));
  20.                     break;
  21.                 case (2): t2.IncSum(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()));
  22.                     break;
  23.             }
  24.             Console.ReadKey();
  25.         }
  26.     }
  27.     class Task1
  28.     {
  29.         static int factorial(int i)
  30.         {
  31.             int result;
  32.             if (i == 1)
  33.                 return 1;
  34.             result = factorial(i - 1) * i;
  35.             return result;
  36.         }
  37.  
  38.         public double t1(int n)
  39.         {
  40.             double result = (Math.Pow((-1), n)) / factorial((n + 1));
  41.             return result;
  42.         }
  43.  
  44.         public double Calculate(int n, double m)
  45.         {
  46.             double sum = 0;
  47.             for (int i = n; i <= m; i++)
  48.             {
  49.                 sum += t1(i);
  50.             }
  51.             Console.WriteLine(sum);
  52.             return sum;
  53.         }
  54.     }
  55.     class Task2
  56.     {
  57.         public double IncSum(int a, int b)
  58.         {
  59.             int temp_a = a, temp_b = b;
  60.             if (a == 0)
  61.             {
  62.                 return b;
  63.             }            
  64.             else if (b == 0)
  65.             {
  66.                 return a;
  67.             }
  68.             if (a != temp_a + temp_b)
  69.             {
  70.                 IncSum(a += 1, b -= 1);
  71.             }
  72.             if (a == temp_a + temp_b)
  73.             {
  74.                 Console.WriteLine(a);
  75.             }
  76.             return a;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement