Zneeky

6. Сума на на естествените числа в интервала [m,n]

Nov 17th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 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.             int f = int.Parse(Console.ReadLine());
  13.             Console.OutputEncoding = Encoding.UTF8;
  14.             Console.WriteLine("Сума на на естествените числа в интервала [n,f] ");
  15.             Console.WriteLine(RecurSum(n,f));
  16.  
  17.         }
  18.         static private int RecurSum(int n,int f)
  19.         {
  20.             if (n == f)
  21.             {
  22.                 return n;
  23.             }
  24.            
  25.  
  26.             return RecurSum(n,f - 1) + f;
  27.         }
  28.     }
  29. }
Add Comment
Please, Sign In to add comment