Advertisement
MyOnAsSalat

Untitled

May 28th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. public class main
  3. {
  4.  
  5.     public static void Main(String[] args)
  6.     {
  7.         Console.WriteLine("Введите первый челен геометрической прогрессии:");
  8.         int b = Convert.ToInt32(Console.ReadLine());
  9.         Console.WriteLine("Введите знаменатель геометрической прогрессии:");
  10.         int q = Convert.ToInt32(Console.ReadLine());
  11.         Console.WriteLine("Введите i:");
  12.         int i = Convert.ToInt32(Console.ReadLine());
  13.         Console.WriteLine("Введите k:");
  14.         int k = Convert.ToInt32(Console.ReadLine());
  15.         Console.WriteLine(Rec(b,q,i,k));
  16.     }
  17.  
  18.     public static int Rec(int b, int q, int i, int k, int sum = 0, int index = 0)
  19.     {
  20.         index++;
  21.         if (index == k + 1) return sum;
  22.         if (index >= i)
  23.         {
  24.             sum += b;
  25.         }
  26.         b *= q;
  27.         return Rec(b, q, i, k, sum, index);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement