Tech Study

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

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

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

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

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

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more