﻿ C# Sharp Exercises: Recursive Function : To calculate the Fibonacci number of a specific term - w3resource

C# Sharp Exercises: Function : To calculate the Fibonacci number of a specific term

C# Sharp Function: Exercise-12 with Solution

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

Pictorial Presentation:

Sample Solution:

C# Sharp Code:

``````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: ");

Console.WriteLine("\nThe Fibonacci of {0} th term  is {1} \n", num, Fib(num));
}
}
```
```

Sample Output:

```Recursive Function : To calculate the Fibonacci number of a specific term :
-------------------------------------------------------------------------------
Enter a number: 10

The Fibonacci of 10 th term  is 55
```

Flowchart :

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

﻿

New Content: Composer: Dependency manager for PHP, R Programming