Q:

Write a program in C# Sharp to create a recursive function to calculate the Fibonacci number of a specific term

0

Write a program in C# Sharp to create a recursive function to calculate the Fibonacci number of a specific term. 
Test Data :
Enter a number: 10
Expected Output :
The Fibonacci of 10 th term is 55

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class funcexer12
{
 public static int Fib(int n1)
 {
  //if ( (n1 == 1) || (number == 2) )
    if (n1 <=2)
      return 1;
      else
      return Fib( n1 - 1 ) + Fib( n1 - 2 );
 }  
 public static void Main()
 {
      int num; 
	  Console.Write("\n\nRecursive Function : To calculate the Fibonacci number of a specific term :\n");
      Console.Write("-------------------------------------------------------------------------------\n");   
      Console.Write("Enter a number: ");
      num = Convert.ToInt32( Console.ReadLine() );
   
      Console.WriteLine("\nThe Fibonacci of {0} th term  is {1} \n", num, Fib(num));
 }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now