get Fibonacci Number - CSharp System

CSharp examples for System:Math Number

Description

get Fibonacci Number

Demo Code


using System;//from  ww w  .j  ava  2  s  .  c  o  m

public class Main{
        public static int getFibonacciNumber(int n) {
         if (n <= 0) {
            return 0;
         }

         if (n == 1) {
            return 1;
         }

         if (n == 2) {
            return 2;
         }

         return getFibonacciNumber(n - 2) + getFibonacciNumber(n - 1);
      }
}

Related Tutorials