Question

In: Computer Science

C# Assignment4A: Fibo-what? If you’ve never heard of the Fibonacci series, it’s an infinite series that...

C#

Assignment4A: Fibo-what? If you’ve never heard of the Fibonacci series, it’s an infinite series that occurs everywhere in nature. It starts off with two digits – 0 and 1. To get the next value in the series, you add the previous two values. In this case, the third value is 0+1 = 1. The fourth value is 1+1 = 2, the fifth 1+2=3 and so on, to give us a series like:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34,...

I always wondered what it would look like if you changed the starting values from 0 and 1 to some arbitrary (and if it would matter). We’re going to do that here. Ask the user for a pair of starting values as well as a number of times to iterate the series, then produce the correct output. We recommend you use a FOR loop and use a sum variable.

For part 1 of this assignment, design pseudocode to solve this problem. When working on the source code, call the file name Assignment4A(.java, .cs, .cpp) and the class name Assignment4A. When printing the next value in the series, print the comma first. The first two values are special cases for printing.

  

Sample Output #1: Enter seed 1:
5
Enter seed 2:

8

   Number of iterations:

10

5,8,13,21,34,55,89,144,233,377,610,987

Sample Output #2: Enter seed 1:
56
Enter seed 2:

78

   Number of iterations:

6

   56,78,134,212,346,558,904,1462

Solutions

Expert Solution

SOLUTION-
I have solve the problem in C# code with comments and screenshot for easy understanding :)

CODE-

using System;
      public class Fibonacci
       {
         public static void Main(string[] args)
          {
             int n1, n2, sum, i, num;
           
             Console.Write("Enter seed 1: ");
             n1 = int.Parse(Console.ReadLine());                       // taking input of the first number
           
             Console.Write("Enter seed 2: ");
             n2 = int.Parse(Console.ReadLine());                       // taking input of the second number
           
             Console.Write("Number of iterations: ");  
             num = int.Parse(Console.ReadLine());                      // taking input of the number of items other than first two
           
             Console.Write(n1+","+n2+",");                             // printing the first two number
           
             for(i=2; i<num+2; ++i)                                    // iterating the loop
             {  
              sum = n1+n2;                                             // calculating the next item which is the sum of previous two
              Console.Write(sum+",");                                  // printing the next number
              n1 = n2;                                                 // storing the numbers for the next iterations
              n2 = sum;  
             }  
          }
       }


SCREENSHOT-


IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

In a blog Mr Bill Gates wrote, “You’ve probably never heard of CGIAR, but they are...
In a blog Mr Bill Gates wrote, “You’ve probably never heard of CGIAR, but they are essential to feeding our future.” Do you agree with Mr Gates? Why, Why not? Explain your answers with relevant information.
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics...
The Fibonacci sequence is an infinite sequence of numbers that have important consequences for theoretical mathematics and applications to arrangement of flower petals, population growth of rabbits, and genetics. For each natural number n ≥ 1, the nth Fibonacci number fn is defined inductively by f1 = 1, f2 = 2, and fn+2 = fn+1 + fn (a) Compute the first 8 Fibonacci numbers f1, · · · , f8. (b) Show that for all natural numbers n, if α...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers...
. (a) Write a C++ program to find Fibonacci numbers. (For the definition of Fibonacci numbers and the recursive formula please refer to problem 5 of Chapter 2 at page 81 in the text-book.) The program asks the user to input an integer and outputs the corresponding Fibonacci number. For example, if the user inputs 4, the program outputs the fifth Fibonacci number, which is 3. Introduce two local variables in the recursion function (suppose we call it fib(n)), one...
What are some other examples of sexist comments you’ve heard throughout your life? Are there certain...
What are some other examples of sexist comments you’ve heard throughout your life? Are there certain spaces where you’re more likely to hear them? B)     Can you remember the first time you heard an “everyday” sexist comment? In what ways have these comments shaped your paths — for good and bad? C)     How do you think everyday sexism affects women’s college experiences? What about their career paths?
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1,...
Python: Using Jupyter Notebook 1. Write code to generate Fibonacci series. Fibonacci numbers – 1, 1, 2, 3, 5, 8, … 2. Check if a number is an Armstrong number A positive integer is called an Armstrong number of order n if abcd... = a^n + b^n + c^n + d^n + ... In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153 = 1*1*1...
5. What are some arguments you’ve heard against evolution? What arguments would you present to counter...
5. What are some arguments you’ve heard against evolution? What arguments would you present to counter them?
5. What are some arguments you’ve heard against evolution? What arguments would you present to counter...
5. What are some arguments you’ve heard against evolution? What arguments would you present to counter them?
There are many applications of the Fibonacci series both in mathematics and in the real world....
There are many applications of the Fibonacci series both in mathematics and in the real world. The Fibonacci series is obtained by starting with 0 and 1, and each subsequent term in the series is obtained by adding the previous two terms. Given n in the top row of the table below, the numbers in the second row represent Fib(n), the numbers in the Fibonacci series. So Fib(0) = 0, and Fib(1) = 1. Then Fib(2)is obtained by adding Fib(0)and...
The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are...
The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not 5. Your assignment...
How would you describe "self-awareness" to someone who has never heard of this concept, and what...
How would you describe "self-awareness" to someone who has never heard of this concept, and what steps might you offer this person if he/she wanted to reach a higher level of self-awareness?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT