﻿ C# Sharp Exercises: Find the Fibonacci numbers for a n numbers of series - w3resource

# C# Sharp Exercises: Find the Fibonacci numbers for a n numbers of series

## C# Sharp Recursion: Exercise-10 with Solution

Write a program in C# Sharp to find the Fibonacci numbers for a n numbers of series using recursion.

Sample Solution:-

C# Sharp Code:

``````using System;

class RecExercise10
{
public static int FindFibonacci(int n)
{
int p = 0;
int q = 1;
for (int i = 0; i < n; i++)
{
int temp = p;
p = q;
q = temp + q;
}
return p;
}

static void Main()
{
Console.WriteLine("\n\n Recursion : Find the Fibonacci numbers for a n numbers of series :");
Console.WriteLine("-----------------------------------------------------------------------");

Console.Write(" Input number of terms for the Fibonacci series : ");
Console.Write("\n The Fibonacci series of {0} terms is : ",n1);
for (int i = 0; i < n1; i++)
{
Console.Write("{0} ",FindFibonacci(i));
}
}
}
```
```

Sample Output:

``` Recursion : Find the Fibonacci numbers for a n numbers of series :
-----------------------------------------------------------------------
Input number of terms for the Fibonacci series : 10

The Fibonacci series of 10 terms is : 0 1 1 2 3 5 8 13 21 34
```

C# Sharp Code Editor:

```using System;

class RecExercise10
{
public static int FindFibonacci(int n)
{
int p = 0;
int q = 1;
for (int i = 0; i < n; i++)
{
int temp = p;
p = q;
q = temp + q;
}
return p;
}

static void Main()
{
Console.WriteLine("\n\n Recursion : Find the Fibonacci numbers for a n numbers of series :");
Console.WriteLine("-----------------------------------------------------------------------");

Console.Write(" Input number of terms for the Fibonacci series : ");