﻿ C# Sharp Exercises: Function : To display the n number Fibonacci series - w3resource

# C# Sharp Exercises: Function: To display the n number Fibonacci series

## C# Sharp Function: Exercise-8 with Solution

Write a program in C# Sharp to create a function to display the n number Fibonacci sequence.

Pictorial Presentation:

Sample Solution:

C# Sharp Code:

``````using System;
class funcexer8
{
public static int Fibo(int nno)
{
int num1 = 0;
int num2 = 1;

for (int i = 0; i < nno; i++)
{
int temp = num1;
num1 = num2;
num2 = temp + num2;
}
return num1;
}
public static void Main()
{
Console.Write("\n\nFunction : To display the n number Fibonacci series :\n");
Console.Write("------------------------------------------------------------\n");
Console.Write("Input number of Fibonacci Series : ");
int n= Convert.ToInt32(Console.ReadLine());

Console.WriteLine("The Fibonacci series of "+n+" numbers is :");
for (int i = 0; i < n; i++)
{
Console.Write(Fibo(i)+"  ");
}
Console.WriteLine();
}
}
```
```

Sample Output:

```Function : To display the n number Fibonacci series :
------------------------------------------------------------
Input number of Fibonacci Series : 10
The Fibonacci series of 10 numbers is :
0  1  1  2  3  5  8  13  21  34
```

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