Write a program to find the sum of 1st 10 numbers of Fibonacci series i.e. 1,1,2,3,5,8,13….
Fibonacci series is such a series which starting from 1 and 1, and subsequent numbers are the
sum of the previous two numbers.
Answers
Required Answer:-
Question:
- Write a program to find the sum of 1st ten numbers of Fibonacci Series.
Solution:
This is an easy question. Read this post to get your answer.
Here is the program. This is written in Java.
public class FibonacciSum {
public static void main(String[] args) {
int a=1, b=0, c=1, sum=0;
for(int i=1;i<=10;i++) {
c=a+b;
a=b;
b=c;
sum+=c;
}
System.out.println("Sum is: "+sum);
}
}
★ We need to find each term of the Fibonacci series and add them up. We will store the sum in a variable and display it. Each term of the Fibonacci series is the sum of previous two terms.
Output is attached.
Question:
Write a program to find the sum of 1st 10 numbers of Fibonacci series, i.e. 1,1,2,3,5,8,13…. Fibonacci series is such a series which starting from 1 and 1, and subsequent numbers are the sum of the previous two numbers.
Solution:
Language used: Java
public class FibSum
{
static void main()
{
int i,a=1,b=0,c;
System.out.println("Fibonacci series =");
for(i=1;i<=10;i++)
{
c=a+b;
System.out.print(c+" ");
a=b;
b=c;
}
}
}