Answer to Question #296867 in C# for chi

Question #296867

Topic: Function

Write a function-­‐oriented program that generates the Fibonacci series numbers of n (as input) and display them. In Fibonacci, the current third number is the sum of two previous

numbers.

Note: you can choose any looping statement if need.


1
Expert's answer
2022-02-13T09:42:40-0500
using System;
using System.Collections.Generic;
using System.Globalization;


namespace App
{
    class Program
    {


        static void Fibonacci(int n)
        {
            int[] fibonacciSequence = new int[n];
            fibonacciSequence[0] = 1;
            fibonacciSequence[1] = 1;
            for (int i = 2; i < fibonacciSequence.Length; i++)
            {
                fibonacciSequence[i] = fibonacciSequence[i - 1] + fibonacciSequence[i - 2];
            }
            Console.Write("Fibonacci Sequence: ");
            for (int i = 0; i < fibonacciSequence.Length; i++)
            {
                Console.Write("{0} ", fibonacciSequence[i]);
            }
            Console.WriteLine();
        }


        static void Main(string[] args)
        {
            Console.Write("Enter n: ");
            int n = int.Parse(Console.ReadLine());
            Fibonacci(n);
            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS