Answer to Question #295223 in C# for playhard

Question #295223

Create a program generate the Fibonacci Sequence and compute for the

corresponding sum based on the generated sequences.

Sample output:

Enter how many: 5

Fibonacci Sequence: 1 1 2 3 5

Sum of Sequence: 12


1
Expert's answer
2022-02-08T10:17:30-0500


using System;
using System.Collections.Generic;
using System.Globalization;


namespace App
{
    class Program
    {


        static void Main(string[] args)
        {
            Console.Write("Enter how many: ");
            int n = int.Parse(Console.ReadLine());
            int sum = 0;
            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]);
                sum += fibonacciSequence[i];
            }
            Console.WriteLine();
            Console.WriteLine("Sum of Sequence: {0}", sum);




            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