C# Sharp Exercises: Function: To display the n number Fibonacci sequence
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
Previous: Write a program in C# Sharp to create a function to calculate the result of raising an integer number to another.
Next: Write a program in C# Sharp to create a function to check whether a number is prime or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework