Question

C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a...

C# - Using Visual Studio 2017/2019

The Fibonacci sequence is a numerical sequence that follows a simple pattern: 1,1, 2, 3, 5, 8, 13, 21, 34, 55, By definition, the first two numbers are 1 and 1, and each subsequent number is the sum of the previous two.

For your program, you will ask the user to enter a number, n, and then calculate and display the values of the Fibonacci sequence to the nth position.

==sample output==

Enter an integer value to see the Fibonacci sequence to that position: 15

The values of the Fibonacci sequence to the 15th position are:

1

1

2

3

5

8

13

21

34

55

89

144

233

377

610

Press any key to continue...

==What i have so far==

class Sequences_For
{
static int Fib(int n)
{
int a = 0;
int b = 1;
for (int i = 1; i < n; i++)
{
int c = a;
a = b;
b = c + b;
}

}

your help is greatly appreciated !

0 0
Add a comment Improve this question Transcribed image text
Answer #1
using System;

class Sequences_For
{
    static int Fib(int n)
    {
        int a = 1, b = 1;
        for (int i = 1; i < n; i++)
        {
            int c = a;
            a = b;
            b = c + b;
        }

        return a;
    }

    public static void Main()
    {
        Console.Write("Enter an integer value to see the Fibonacci sequence to that position: ");
        int n = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("The values of the Fibonacci sequence to the " + n + "th position are:");
        for (int i = 1; i <= n; i++)
        {
            Console.WriteLine(Fib(i));
        }
    }
}

Enter an integer value to see the Fibonacci sequence to that position: 15 The values of the Fibonacci sequence to the 15th po

Add a comment
Know the answer?
Add Answer to:
C# - Using Visual Studio 2017/2019 The Fibonacci sequence is a numerical sequence that follows a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in...

    Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in the sequence (after the first two) is the sum of the previous two. Write a program that computes and outputs the nth Fibonacci number, where n is a value entered by the user. The Fibonacci Sequence 1,1,2,3,5,8,13.21,34,55,89,144,233,377... 1+12 13+2134 1+23 21+34-55 2-35 34+55-09 3+58 56+89144 5+8=13 89+144233 8+13-21 144+233 377 5

  • Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...

    Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5,...

    in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89.. 1 See the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence (the oth number if Fib(0)-0): 8 Fib(N)-/N, if N 0 or 1 ifN> 1 Fib(N-2) Fib(N-1), a. b. c. Write a recursive version of the function Fibonacci. Write...

  • Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 =...

    Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1, where i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers. Write a recursive function definition in C++ that has one parameter n of type int and that returns the n-th Fibonacci number. You can call this function inside the main function to print the Fibonacci numbers. Sample Input...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the...

    Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the linear recurrence equation Fn F-1 F-2 where F F2 1 and by convention Fo 0. For example, the first 8 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21. (a) For a given n, compute the nth Fibonnaci number using a for loop (b) For a given n, compute the nth Fibonnaci number using a while loop Print the 15th Fibonacci number...

  • Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int...

    Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int n){ int a = 0,b = 1,c; if(n == 0 || n == 1){ return n; } while(n>2){ c = b + a; a = b; b = c; n--; } return c; } int main(){ int n; cout<<"Enter n: "; cin>>n; int result = fib(n); cout<<"Fib("<<n<<") = "<<result<<endl; return 0; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT