Advertisement
BojidarDosev

Fibonachi zadacha klas s rekurciq

Sep 30th, 2021
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 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 ConsoleApp23
  8. {
  9.     class Program
  10.     {
  11.         static void Pechat (int n)
  12.         {
  13.             Console.WriteLine(n);
  14.             if (n > 1) Pechat(n - 1);
  15.         }
  16.         static int Fib(int n)
  17.         {
  18.             if (n == 1) return 1;
  19.             if (n == 2) return 1;
  20.             return Fib(n - 1) + Fib(n - 2);
  21.         }
  22.          
  23.         static void Main(string[] args)
  24.         {
  25.             Console.WriteLine(Fib(7));
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement