Advertisement
Rolex_

Task_Progression

Jun 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 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 Task2_Progression
  8. {
  9.     class Program
  10.     {
  11.         public static int MultiArethProgression(int a1, int t, int n)
  12.         {
  13.             if (n == 0) return 1;
  14.  
  15.             return a1 * MultiArethProgression(a1 + t, t, n - 1);
  16.         }
  17.  
  18.         public static double MultiGeomProgression(double a1, double t, int n)
  19.         {
  20.             if (n == 0) return 0;
  21.  
  22.             if (n == 1) return a1;
  23.  
  24.             int ratio = n - 1;
  25.  
  26.             return (a1 / t) * MultiGeomProgression(a1, t, ratio);
  27.         }
  28.  
  29.         static void Main(string[] args)
  30.         {
  31.             Console.WriteLine("(2) Задача\n" + "Подзадача №1");
  32.  
  33.             InitializeArethProgression(out int A1, out int N, out int T);
  34.             Console.WriteLine("Произведение n элементов: " + MultiArethProgression(A1, T, N));
  35.  
  36.             Console.ReadKey(true);
  37.             Console.Clear();
  38.  
  39.             InitializeGeomProgression(out int first, out int A_n, out int q);
  40.             Console.WriteLine("Произведение n элементов: " + MultiGeomProgression(first, A_n, q));
  41.         }
  42.  
  43.         private static void InitializeArethProgression(out int A1, out int N, out int T)
  44.         {
  45.             Console.Write("Введите первый элемент ариф. прогрессии: ");
  46.             A1 = int.Parse(Console.ReadLine());
  47.             Console.Write("Введите число элементов ариф. прогрессии: ");
  48.             N = int.Parse(Console.ReadLine());
  49.             Console.Write("Введите шаг ариф. прогрессии: ");
  50.             T = int.Parse(Console.ReadLine());
  51.         }
  52.  
  53.         private static void InitializeGeomProgression(out int first, out int A_n, out int q)
  54.         {
  55.             Console.Write("Введите первый элемент геометр. прогрессии: ");
  56.             first = int.Parse(Console.ReadLine());
  57.             Console.Write("Введите число элементов геометр. прогрессии: ");
  58.             A_n = int.Parse(Console.ReadLine());
  59.             Console.Write("Введите знаменатель (шаг) прогрессии: ");
  60.             q = int.Parse(Console.ReadLine());
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement