Q:

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

0

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

All Answers

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

using System;
 
class functionexcercise
{
    public static int Fibonaccisequence(int number)
    {
        int num1 = 0;
        int num2 = 1;
 
        for (int i = 0; i < number; i++)
        {
            int temp = num1;
            num1 = num2;
            num2 = temp + num2;
        }
        return num1;
    }
    public static void Main()
    {
        Console.Write("Enter a number : ");
        int num = Convert.ToInt32(Console.ReadLine());
 
        Console.WriteLine("The Fibonacci series of " + num + " numbers is :");
        for (int i = 0; i < num; i++)
        {
            Console.Write(Fibonaccisequence(i) + "  ");
        }
        Console.ReadLine();
    }
}

Result:

Enter a number : 10

The Fibonacci series of 10 numbers is :

0  1  1  2  3  5  8  13  21  34

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

total answers (1)

Write a C# program to Print Binary Equivalent of a... >>
<< Write a C# program to create a function to swap th...