Advertisement
vencinachev

Recursions

Nov 24th, 2020
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using java.util;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace SoftSvetlina
  10. {
  11.     class Program
  12.     {
  13.         static int Factorial(int n)
  14.         {
  15.             if (n == 0)
  16.             {
  17.                 return 1;
  18.             }
  19.             return Factorial(n - 1) * n;
  20.         }
  21.  
  22.         static void CountDown(int start)
  23.         {
  24.             if (start == -10)
  25.             {
  26.                 return;
  27.             }
  28.             Console.WriteLine(start);
  29.             CountDown(start - 1);
  30.         }
  31.  
  32.         static int fib(int n)
  33.         {
  34.             if (n == 0)
  35.             {
  36.                 return 0;
  37.             }
  38.             else if (n == 1)
  39.             {
  40.                 return 1;
  41.             }
  42.             return fib(n - 1) + fib(n - 2);
  43.         }
  44.         static void Main()
  45.         {
  46.             Console.WriteLine(fib(12));
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement