Question

In: Computer Science

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By...

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1,2,3,5,8,13,21,34,55,89,...
By considering the terms in the Fibonacci sequence whose values do not exceed 1000, find the sum of
the all the terms up to 300.

Solutions

Expert Solution

Fibonacci Sequence:

A series of numbers in which each number is the sum of the two preceding numbers. The actual sequence of numbers will starts from 0 and the second number is 1. But 0+1 is equal to 1, we will not consider the value of 0 in the fibonacci sequence.

According to the given question, we have to find out the fibonacci sequence of numbers upto 300. And we have to add the obtained numbers. Below i am providing the C program according to the given conditions in the question.

Raw Code for the given problem:

#include<stdio.h>
int main()
{
/*these are the variables we use to write the code.
i is to get the fibonacci series and sum of that series using for loop.
n is the number which is used to calculate according to our requirement.
t1 is the starting initialization of the series.
t2 is the next number to be added to obtain the fibonacci series.
nextTerm variable is to find the next term of the series.
*/
int i,n,t1=0,t2=1,nextTerm;
//sum variable is initialized to 0 at first and used to calcute the sum of the fibonacci sequence obtained
int sum=0;
//Asking for the user input for the range that we want
printf("Enter the value for n:");
//Scaning the input that we give to the system.
scanf("%d",&n);
//using for loop for the fibonacci sequence
   for(i=1;t1<=n;i++)
   {
       //Printing the fibonacci numbers upto required range
       printf("%d\n",t1);
       //nextTerm is obtained by adding two of its preceeding numbers
       nextTerm = t1 + t2;
       //Below is the logic to get fibonacci sequence
       t1 = t2;
       t2 = nextTerm;
       //To get the sum of the fibonacci sequence that we obtained.
       sum=sum+t1;
   }
//Printing the fibonacci sequence sum.
printf("The sum of the fibonacci series less than 300 is:%d",sum);
}

Source Code for given problem:

Out put of the above code:

I have explained the entired code using comments in the program. With those the code will understand easily.

                     Hope the above is helpful. Please feel free to comment if any queries in the

                                 comment section. I will try to solve them as soon as possible.

                                            Do an up vote. Thank you..


Related Solutions

A Fibonacci sequence, is a sequence of numbers with the property that each number is the...
A Fibonacci sequence, is a sequence of numbers with the property that each number is the sum of the two preceding Fibonacci numbers, starting from 0 and 1. Fibonacci number are usually denoted by Fn, where Fn is the nth Fibonacci number. Thus Fn = 0, and Fn = 1, and Fn = Fn-1 + Fn-2, n ≥ 2. Here are the first few Fibonacci numbers: F0=0 (by definition) F1=1 (by definition) F2 = F1 + F0 = 1 +...
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...
PLEASE WRITE IN PYTHON A sequence of integers is said to be Fibonacci-like if each element...
PLEASE WRITE IN PYTHON A sequence of integers is said to be Fibonacci-like if each element of the sequence (except the first two elements) is the sum of the previous two integers in the sequence. For example, the sequence 10, 14, 24, 38, 62, 100, 162, 262 is Fibonacci-like. Note that the first two integers in the above sequence are arbitrary. Each of the remaining integers is the sum of the two integers just before it in the sequence. For...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you...
Consider the Fibonacci sequence 1,1,2,3,5,8,13,21,34,55,89,…. . The first two numbers are 1 and 1. When you add these numbers you get 2 = 1+1, which becomes the third number in the sequence. When you add the second and third numbers, you get 3 = 1+2, which becomes the fourth number in the sequence. When you add the third and fourth numbers, you get 5 = 2+3, which becomes the fifth number in the sequence; and so on to generate the...
For each sequence given below, find a closed formula for an, the nth term of the sequence (assume...
For each sequence given below, find a closed formula for an, the nth term of the sequence (assume the first terms here are always a0) by relating it to another sequence for which you already know the formula. −1,0,7,26,63,124,… an=(n^3)-1 −1,1,7,17,31,49,… an=2n^2-1 0,10,30,60,100,150,..... an=10*((n(n+1))/2) 2,3,6,14,40,152,… an= The first three are correct I can't figure out the last one.
The Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21…… starts with two 1s, and...
The Fibonacci sequence 1, 1, 2, 3, 5, 8, 13, 21…… starts with two 1s, and each term afterward is the sum of its two predecessors. Please write a function, Fib(n), which takes n as the input parameter. It will return the n-th number in the Fibonacci sequence. Using R, the output for Fib(9) should give only the 9th element in the sequence and not any of the previous elements. Please Help :)
An arithmetic sequence has terms a3 = 11.7 and a8 = −14.6. What is the first term?
An arithmetic sequence has terms a3 = 11.7 and a8 = −14.6. What is the first term?
For the following exercises, find the specified term given two terms from an arithmetic sequence. a1 = 33 and a7 = −15. Find a4 .
For the following exercises, find the specified term given two terms from an arithmetic sequence. a1 = 33 and a7 = −15. Find a4 .
Define These Terms in Two Short Paragraph each. One Short Paragraph defining the term, and one...
Define These Terms in Two Short Paragraph each. One Short Paragraph defining the term, and one short paragraph using it in an example. The terms have to relate to international business. 1-Patriotism- 2-Colonialism- 3-Ethnocentric- 4-Acculturation- 5-Developed World- 6-Social Cohesion- 7-Microcredit Banking- 8-Protectionism- 9-Culture- 10-Globalization-
Define the term “Expenditure” and distinguish between that term and each of the following terms: 1....
Define the term “Expenditure” and distinguish between that term and each of the following terms: 1. Expense 2. Disbursement 3. Encumbrance
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT