Given an integer N, the task is to find the sum of numbers from 1 to N which are in Fibonacci sequence.
First few Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21, 34, ….
Input: N = 5
1 + 1 + 2 + 3 + 5 = 12
Input: N = 10
1 + 1 + 2 + 3 + 5 + 8 = 20
- Loop through all the Fibonacci numbers which are less than N.
- Initialize a sum variable with 0.
- Keep on adding these Fibonacci numbers to get the required sum.
Below is the implementation of the above approach:
- Look-and-Say Sequence
- Maximum sum of distinct numbers such that LCM of these numbers is N
- Find if given number is sum of first n natural numbers
- Program for Fibonacci numbers in PL/SQL
- Find product of prime numbers between 1 to n
- Largest of two distinct numbers without using any conditional statements or operators
- Algorithm to generate positive rational numbers
- Introduction of Hyperledger
- Comparison Networks
- MongoDB - Embedded Documents
- HijrahDate getEra() method in Java with Example
- HijrahDate getChronology() method in Java with Example
- HijrahDate equals() method in Java with Example
- HijrahDate atTime() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.