Zneeky

5. Сума на първите н-члена

Nov 17th, 2021 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.  
  11.             int n = int.Parse(Console.ReadLine());
  12.             Console.OutputEncoding = Encoding.UTF8;
  13.             Console.WriteLine("Сума на първите n-члена рекурсивно: ");
  14.             Console.WriteLine(RecurSum(n));
  15.  
  16.         }
  17.         static private int RecurSum(int n)
  18.         {
  19.             if (n ==0)
  20.             {
  21.                 return 0;
  22.             }
  23.            
  24.  
  25.             return RecurSum(n - 1) + n;
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment